summary refs log tree commit diff stats
path: root/zsh
diff options
context:
space:
mode:
authorAlan Pearce2017-04-25 12:44:13 +0200
committerAlan Pearce2017-04-25 12:44:13 +0200
commite9d22a78a393d2c2e8d4c92c6d39dad8352f49fa (patch)
tree211eb9b24fd017bcf5968a9b05f501e935db8985 /zsh
parent7aa006027e6a4d267bdfde0d5a3cf9a3a0377221 (diff)
downloaddotfiles-e9d22a78a393d2c2e8d4c92c6d39dad8352f49fa.tar.lz
dotfiles-e9d22a78a393d2c2e8d4c92c6d39dad8352f49fa.tar.zst
dotfiles-e9d22a78a393d2c2e8d4c92c6d39dad8352f49fa.zip
zsh: Create function & widget to cd into ghq projects
Diffstat (limited to 'zsh')
-rw-r--r--zsh/.config/zsh/.zshrc20
1 files changed, 20 insertions, 0 deletions
diff --git a/zsh/.config/zsh/.zshrc b/zsh/.config/zsh/.zshrc
index 62feedc..d72307d 100644
--- a/zsh/.config/zsh/.zshrc
+++ b/zsh/.config/zsh/.zshrc
@@ -234,6 +234,26 @@ then
             -name .git -prune -o -name .svn -prune -o -type d \
             -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'
   }
+
+  fp () {
+    ghq look $(ghq list | fzf +m)
+  }
+  cd-project-widget () {
+    local cmd="ghq list"
+    setopt localoptions pipefail 2> /dev/null
+    local dir="$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" fzf +m)"
+    if [[ -z "$dir" ]]; then
+      zle redisplay
+      return 0
+    fi
+    cd $(ghq list --full-path | grep "$dir")
+    local ret=$?
+    zle reset-prompt
+    typeset -f zle-line-init >/dev/null && zle zle-line-init
+    return $ret
+  }
+  zle -N cd-project-widget
+  bindkey '\es' cd-project-widget
 fi
 
 unsetopt flow_control       # Let me use ^S and ^Q