summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2019-08-26 08:54:05 +0200
committerFlorian Pritz <bluewind@xinu.at>2019-10-08 15:59:44 +0200
commitac5b94f4663568640fd9a06033ff3a8c64b0a809 (patch)
treef425f0606ee6ae160b67b90b7853d7581b09841e
parentc16ee1e0d3a939e053e96d49c64b1bc60e15a25c (diff)
downloaddotfiles-ac5b94f4663568640fd9a06033ff3a8c64b0a809.tar.gz
dotfiles-ac5b94f4663568640fd9a06033ff3a8c64b0a809.tar.xz
zshrc: Add project cd hotkey
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--.zshrc34
1 files changed, 34 insertions, 0 deletions
diff --git a/.zshrc b/.zshrc
index ab08cc3..0e45a81 100644
--- a/.zshrc
+++ b/.zshrc
@@ -281,6 +281,38 @@ fzf-hosts-widget() {
return $ret
}
+__fproject() {
+ local startdir="$PWD"
+ if git rev-parse --show-toplevel &>/dev/null; then
+ startdir=$(git rev-parse --show-toplevel)
+ elif [[ $PWD == $HOME ]]; then
+ startdir="$HOME/projects"
+ fi
+
+ find "$startdir" -type d -not \( \( -path '*/vendor' -or -path '*/.git' \) -prune \) | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS" $(__fzfcmd) -m "$@" | while read item; do
+ echo -n "${(q)item}"
+ done
+ local ret=$?
+ echo
+ return $ret
+}
+
+fzf-projects-widget() {
+ local _dir=$(__fproject)
+ local ret=$?
+ if [[ "$_dir" == *"'"* ]] || [[ "$_dir" == "" ]]; then
+ printf "%s\n" "ERROR: Invalid dir name for widget: '$_dir'" >&2
+ zle reset-prompt
+ return 1
+ fi
+
+ zle push-line
+ LBUFFER="cd '${_dir}'"
+ zle accept-line
+ zle reset-prompt
+ return $ret
+}
+
if type fzf &>/dev/null; then
zle -N fzf-history-widget
bindkey '^R' fzf-history-widget
@@ -288,6 +320,8 @@ if type fzf &>/dev/null; then
bindkey '^T' fzf-file-widget
zle -N fzf-hosts-widget
bindkey '^H' fzf-hosts-widget
+ zle -N fzf-projects-widget
+ bindkey '^P' fzf-projects-widget
fi
# }}}