Просмотр исходного кода

Collate misc zsh alias, refactor git detection

Also update git file comments and oh-my-zsh version.
Weiyi Lou 10 лет назад
Родитель
Сommit
9508c0ea60

+ 10 - 0
zsh/custom/aliases-misc.zsh

@@ -0,0 +1,10 @@
+# Hosts file
+alias hosts='sudo vim /etc/hosts'
+
+# Common places
+alias cd.='cd ~/dotfiles'
+
+# Folder listing/traversal, least to most detailed
+alias l='ls'
+alias la='ls -A'
+alias lal='ls -Alh'

+ 0 - 4
zsh/custom/auto-ssh-hosts.zsh

@@ -1,10 +1,6 @@
 # Automagic ssh to known hosts.
 #
 # Works in conjunction with .ssh/config for username@hostname
-
-## hosts file
-alias hosts='sudo vim /etc/hosts'
-
 local _myhosts
 _myhosts=( ${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*} )
 

+ 0 - 4
zsh/custom/correction.zsh

@@ -1,4 +0,0 @@
-# Don't suggest corrections for these commands, in inclusion to omz's defaults
-alias cp='nocorrect cp'
-alias ln='nocorrect ln'
-alias touch='nocorrect touch'

+ 40 - 45
zsh/custom/git.zsh

@@ -1,54 +1,59 @@
-# preferred git shortcuts, not in the git plugin
-
-#compare the provided version of git to the version installed and on path
-#prints 1 if input version <= installed version
-#prints -1 otherwise
+# Check the installed git against a given version number
+#
+# Prints 1 if installed > input.
+# Prints -1 if installed < input.
+# Prints 0 if they are the same.
 function git_compare_version() {
-  local INPUT_GIT_VERSION=$1;
-  local INSTALLED_GIT_VERSION
-  INPUT_GIT_VERSION=(${(s/./)INPUT_GIT_VERSION});
-  INSTALLED_GIT_VERSION=($(command git --version 2>/dev/null));
-  INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]});
+  # Sanitise input. Remove dots, right-pad 0's to 3 digits.
+  INPUT=${1//./}
+  INPUT=$(echo $INPUT | sed -e '
+    :again
+    s/^.\{1,2\}$/&0/
+    t again'
+  )
+  # Sanitise installed version to 3 digits as well.
+  INSTALLED=$(git --version 2> /dev/null)
+  INSTALLED=${INSTALLED//[git version |.]/}
 
-  for i in {1..3}; do
-    if [[ $INSTALLED_GIT_VERSION[$i] -gt $INPUT_GIT_VERSION[$i] ]]; then
-      echo 1
-      return 0
-    fi
-    if [[ $INSTALLED_GIT_VERSION[$i] -lt $INPUT_GIT_VERSION[$i] ]]; then
-      echo -1
-      return 0
-    fi
-  done
-  echo 1
+  if [[ $INSTALLED -gt $INPUT ]]; then
+    echo 1
+  elif [[ $INSTALLED -lt $INPUT ]]; then
+    echo -1
+  else
+    echo 0
+  fi
   return 0
 }
-POST_1_8_3_GIT=$(git_compare_version "1.8.3")
-unset -f git_compare_version
 
-# As of git 1.8.3 decorations can be coloured automatically according to what
-# they are i.e. tags, branches, etc.
-if [[ $POST_1_8_3_GIT -gt 0 ]]; then
+# Prepare compact git log (`gl`) format
+#
+# Log displays train tracks, decorations, users and dates.
+if [[ $(git_compare_version "1.8.3") -ge 0 ]]; then
   DECO_COLOUR='%C(auto)'
 else
   DECO_COLOUR='%Cgreen'
 fi
 GIT_LOG_PRETTY="'format:%C(yellow)%h %Creset%ad %Cblue%an:$DECO_COLOUR%d %Creset%s'"
-# Log displays train tracks, decorations, users and dates
 GIT_LOG_DEFAULTS="--graph --date=short --pretty=$GIT_LOG_PRETTY"
 
+# Useful oh-my-zsh git plugin aliases:
+#
+#     ga, gc, gco, gb, gba, gm, grhh, grb/grba/grbc, gwip, gunwip
+#
+# Aliases not in the git plugin:
 alias ga.='git add -A .'
 alias gap='git add -p'
 alias gbav='git branch -av'
 alias gbd='git branch -D'
 alias gbv='git branch -v'
 alias gcob='git checkout -b'
+alias gcop='git checkout -p'
 alias gds='git diff --staged'
 alias gf='git fetch --all --tags && git fetch --all --prune'
 alias ggpush='git push -u origin $(current_branch)'
 alias gl="git log $GIT_LOG_DEFAULTS"
-alias gla='gl --all' # show all refs, not just current branch history.
-alias glb='gl --simplify-by-decoration' # concise branch and tag log.
+alias gla='gl --all' # show all refs, not only those reachable from current branch.
+alias glb='gl --simplify-by-decoration' # show mostly branches and tags.
 alias glh="git --no-pager log --max-count=15 $GIT_LOG_DEFAULTS" # show first few.
 alias glp='git log --graph --decorate -p'
 alias gls='git log --graph --decorate --stat'
@@ -57,40 +62,30 @@ alias grh='git reset --hard'
 alias grs='git reset --soft'
 alias gs='git status'
 alias gsr='git show --format=raw' # all info about a commmit.
-compdef ggpush=git
 
-# searching history.
+# Searching history.
 alias glG='git log --stat -G' # Search DIFFS - changes with given text.
 alias glS='git log --stat -S' # Search DIFFS - changes in number of given text.
-alias glg='git log --grep' # search commit MESSAGES.
+alias glg='git log --grep' # Search MESSAGES.
 
-# git submodule management.
+# Submodule management.
 alias gsm='git submodule'
 alias gsmpull='git submodule foreach git pull origin master'
 alias gsmup='git submodule sync && git submodule update --init --recursive'
 
-# fix tracking for origin if not there.
+# Fix tracking for origin if not there.
 alias track='git branch --set-upstream-to origin/$(current_branch) && git fetch'
 
-# autosquashing for simple fixups.
+# Autosquashing for simple fixups.
 alias grbi='git rebase -i --autosquash'
 alias gcf='git commit --fixup'
 alias gcs='git commit --squash'
 
-# useful omz git plugin ones include:
-#   ga, gc, gco, gb, gba, gm, grhh, grb, gwip, gunwip
-#
-# ggpush has been removed from oh-my-zsh!
-# ggpush translates into `git push origin <current branch>`.
-
 # Recover indexed/staged changes that were lost.
 #
 # By a careless reset, for example. This function locates all dangling/orphaned
 # blobs and puts them in text files. These files can then be checked for the
-# lost changes.
-#
-# Most tidy method found so far:
-# http://blog.ctp.com/2013/11/21/git-recovering-from-mistakes/
+# lost changes. http://blog.ctp.com/2013/11/21/git-recovering-from-mistakes/
 function git_retrieve_discarded_index_changes() {
   for blob in $(git fsck --lost-found | awk '$2 == "blob" { print $3 }'); do
     git cat-file -p $blob > $blob.txt;

+ 0 - 2
zsh/custom/history.zsh

@@ -1,5 +1,3 @@
-# Quick history
-alias h='history 100'
 # Don't show expansions on return, just execute, e.g. for !! and !$
 setopt nohistverify
 # Don't have the same history across tabs/windows

+ 0 - 8
zsh/custom/ls-and-cd.zsh

@@ -1,8 +0,0 @@
-# folder listing/traversal, least to most detailed
-alias l='ls'
-alias la='ls -A'
-#alias ll='ls -lh'
-alias lal='ls -Alh'
-
-# common places
-alias cd.='cd ~/dotfiles'

+ 1 - 1
zsh/custom/proxy.zsh

@@ -1,6 +1,6 @@
 # Set proxy environment variables
 function setproxy() {
-  proxy_address=${1:-}
+  proxy_address=${1:-} # default value of nothing
   export HTTP_PROXY=$proxy_address
   export HTTPS_PROXY=$proxy_address
   export FTP_PROXY=$proxy_address

+ 1 - 1
zsh/oh-my-zsh

@@ -1 +1 @@
-Subproject commit e44aa50301cbdb9c713193263e6c0c5a9a5798c0
+Subproject commit 22632aac7c99e02ec38223c84b2348435a82d1b5