diff --git a/README.md b/README.md index 0a38f13..e27d7fb 100644 --- a/README.md +++ b/README.md @@ -133,17 +133,20 @@ Useful examples ```sh # vimf - Open selected file in Vim vimf() { - FILE=$(fzf) && vim "$FILE" + local file + file=$(fzf) && vim "$file" } # fd - cd to selected directory fd() { - DIR=$(find ${1:-*} -path '*/\.*' -prune -o -type d -print 2> /dev/null | fzf) && cd "$DIR" + local dir + dir=$(find ${1:-*} -path '*/\.*' -prune -o -type d -print 2> /dev/null | fzf) && cd "$dir" } # fda - including hidden directories fda() { - DIR=$(find ${1:-.} -type d 2> /dev/null | fzf) && cd "$DIR" + local dir + dir=$(find ${1:-.} -type d 2> /dev/null | fzf) && cd "$dir" } # fh - repeat history @@ -155,6 +158,22 @@ fh() { fkill() { ps -ef | sed 1d | fzf -m | awk '{print $2}' | xargs kill -${1:-9} } + +# fbr - checkout git branch +fbr() { + local branches branch + branches=$(git branch) && + branch=$(echo "$branches" | fzf +s +m) && + git checkout $(echo "$branch" | sed "s/.* //") +} + +# fbr - checkout git commit +fco() { + local commits commit + commits=$(git log --pretty=oneline --abbrev-commit) && + commit=$(echo "$commits" | fzf +s +m -e) && + git checkout $(echo "$commit" | sed "s/ .*//") +} ``` Key bindings for command line diff --git a/install b/install index f85f6d3..6578179 100755 --- a/install +++ b/install @@ -111,7 +111,8 @@ __fsel() { } __fcd() { - DIR=$(find ${1:-*} -path '*/\.*' -prune -o -type d -print 2> /dev/null | fzf) && printf 'cd %q' "$DIR" + local dir + dir=$(find ${1:-*} -path '*/\.*' -prune -o -type d -print 2> /dev/null | fzf) && printf 'cd %q' "$dir" } if [ -z "$(set -o | grep '^vi.*on')" ]; then