diff --git a/assets/default/dotfiles/bash_alias b/assets/default/dotfiles/bash_alias index 94572ce..3158fe6 100644 --- a/assets/default/dotfiles/bash_alias +++ b/assets/default/dotfiles/bash_alias @@ -10,3 +10,4 @@ alias tiga='tig --all' # cd alias cd..='cd ..' +source $HOME/.bash_funcs diff --git a/assets/default/dotfiles/bash_funcs b/assets/default/dotfiles/bash_funcs new file mode 100644 index 0000000..3e88b6a --- /dev/null +++ b/assets/default/dotfiles/bash_funcs @@ -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 +} diff --git a/assets/default/dotfiles/tmux.conf b/assets/default/dotfiles/tmux.conf index 469deaa..b0d5a3f 100644 --- a/assets/default/dotfiles/tmux.conf +++ b/assets/default/dotfiles/tmux.conf @@ -27,9 +27,13 @@ setw -g mouse-select-window on setw -g mouse-select-pane on # easy splitting -bind | split-window -h -c "#{pane_current_path}" -bind - split-window -c "#{pane_current_path}" -bind _ split-window -c "#{pane_current_path}" +if-shell "vertest `tmux -V` '>=' 1.9" 'bind | split-window -h -c "#{pane_current_path}"' +if-shell "vertest `tmux -V` '>=' 1.9" '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 setw -g mode-keys vi diff --git a/recipes/default/dotfiles b/recipes/default/dotfiles index 93f511d..49d754f 100644 --- a/recipes/default/dotfiles +++ b/recipes/default/dotfiles @@ -10,3 +10,4 @@ try_link "tmux.conf" "$HOME/.tmux.conf" source_dotfile "bashrc" source_dotfile "bash_profile" source_dotfile "bash_alias" +source_dotfile "bash_funcs"