-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompnav.sh
More file actions
53 lines (47 loc) · 1.93 KB
/
Copy pathcompnav.sh
File metadata and controls
53 lines (47 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Compnav setup. See readme for instructions.
#
# Source this only from interactive shell startup scripts (like .bashrc or zshrc).
#
# As much logic as possible is in the Ruby scripts to minimize the amount of bash gobbledygook.
up() {
local dir
# Pass COMPNAV_FZF_UP_OPTS to fzf if set, or use the default set of options.
#
# --select-1 --exit-0: Don't show the interactive fzf finder if there's 1 or 0 matches.
# --sync --bind 'start:accept': Accepts the first match for you when fzf finishes listing.
dir=$(COMPNAV_FZF_UP_OPTS="${COMPNAV_FZF_UP_OPTS:---select-1 --exit-0 --sync --bind 'start:accept' --height '0%'}" \
ruby "$COMPNAV_DIR/up.rb" "--fzf" "$*") &&
# Expand a leading ~ ourselves. (eval would execute code embedded in dir names.)
cd "${dir/#\~/$HOME}" || return;
}
z() {
local dir
# See comments on up().
dir=$(COMPNAV_FZF_Z_OPTS="${COMPNAV_FZF_Z_OPTS:---select-1 --exit-0}" \
ruby "$COMPNAV_DIR/z.rb" "--fzf" "$*") &&
cd "${dir/#\~/$HOME}" || return;
}
h() {
local dir
# See comments on up().
dir=$(COMPNAV_FZF_H_OPTS="${COMPNAV_FZF_H_OPTS:---select-1 --exit-0}" \
ruby "$COMPNAV_DIR/h.rb" "--fzf" "$*") &&
cd "${dir/#\~/$HOME}" || return;
}
# If the new dir is different than the old dir, update the recent-dirs file.
_compnav_track() {
[ "$OLDPWD" = "$PWD" ] || ruby "$COMPNAV_DIR/z.rb" --add "$PWD"
}
if [ -n "$ZSH_VERSION" ]; then
# zsh's chpwd hook fires on every directory change: cd, pushd/popd, AUTO_CD, cd -.
# add-zsh-hook won't add the hook twice if this file is sourced again.
autoload -Uz add-zsh-hook
add-zsh-hook chpwd _compnav_track
else
# bash has no chpwd hook, so wrap the builtins that change directory.
cd() { builtin cd "$@" || return; _compnav_track; }
pushd() { builtin pushd "$@" || return; _compnav_track; }
popd() { builtin popd "$@" || return; _compnav_track; }
fi
# Add the initial pwd at shell session startup.
ruby "$COMPNAV_DIR/z.rb" --add "$PWD"