Add tmux improvements for version testing

This commit is contained in:
ViViDboarder 2014-11-04 09:40:18 -08:00
parent 70f5fe4ffe
commit 0363735939
4 changed files with 69 additions and 3 deletions

View File

@ -10,3 +10,4 @@ alias tiga='tig --all'
# cd # cd
alias cd..='cd ..' alias cd..='cd ..'
source $HOME/.bash_funcs

View File

@ -0,0 +1,60 @@
#! /bin/bash
# Version compare based on
# http://stackoverflow.com/questions/4023830/bash-how-compare-two-strings-in-version-format
vercomp() {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}
vertest() {
local ver1=($1) op=($2) ver2=($3)
vercomp $ver1 $ver2
case $op in
'=')
[ $? -eq 0 ] && return 0 || return 1
;;
'!=')
[ $? -ne 0 ] && return 0 || return 1
;;
'<')
[ $? -eq 2 ] && return 0 || return 1
;;
'<=')
[ $? -eq 2 -o $? -eq 0 ] && return 0 || return 1
;;
'>')
[ $? -eq 1 ] && return 0 || return 1
;;
'>=')
[ $? -eq 1 -o $? -eq 0 ] && return 0 || return 1
;;
esac
return -1
}

View File

@ -27,9 +27,13 @@ setw -g mouse-select-window on
setw -g mouse-select-pane on setw -g mouse-select-pane on
# easy splitting # easy splitting
bind | split-window -h -c "#{pane_current_path}" if-shell "vertest `tmux -V` '>=' 1.9" 'bind | split-window -h -c "#{pane_current_path}"'
bind - split-window -c "#{pane_current_path}" if-shell "vertest `tmux -V` '>=' 1.9" 'bind - split-window -c "#{pane_current_path}"'
bind _ split-window -c "#{pane_current_path}" if-shell "vertest `tmux -V` '>=' 1.9" 'bind _ split-window -c "#{pane_current_path}"'
# old versions
if-shell "vertest `tmux -V` '<' 1.9" 'bind | split-window -h'
if-shell "vertest `tmux -V` '<' 1.9" 'bind - split-window'
if-shell "vertest `tmux -V` '<' 1.9" 'bind _ split-window'
# act like vim # act like vim
setw -g mode-keys vi setw -g mode-keys vi

View File

@ -10,3 +10,4 @@ try_link "tmux.conf" "$HOME/.tmux.conf"
source_dotfile "bashrc" source_dotfile "bashrc"
source_dotfile "bash_profile" source_dotfile "bash_profile"
source_dotfile "bash_alias" source_dotfile "bash_alias"
source_dotfile "bash_funcs"