-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathautojump-improved.zsh
66 lines (61 loc) · 1.97 KB
/
autojump-improved.zsh
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
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/zsh
# slightly improved autojump command: when a valid path is given,
# jump to that path instead of looking into the autojump database...
j () {
output=$(echo $@)
[ ! -d "$output" ] && output=$(autojump $@)
if [[ -d "$output" ]]; then
echo -e "\\033[31m${output}\\033[0m"
cd "$output"
else
echo -e "\\033[31m.\\033[0m"
fi
}
# slightly improved autojump command: when a valid path is given,
# jump to that path instead of looking into the autojump database...
# also, don't jump to folders not contained in current folder.
jd () {
output=$(echo $(pwd)/$@)
[ ! -d "$output" ] && output=$(autojump $(pwd) $@)
if [[ $output == *"$(pwd)"* && -d "$output" ]];then
echo -e "\\033[31m${output}\\033[0m"
cd "$output"
else
echo -e "\\033[31m.\\033[0m"
fi
}
# an autojump-like method for "jumping" into a directory based on fzf:
# advantage: see where you are going to jump before actually jumping
f () {
output=$(autojump --stat | head --lines=-7 | sed 's/.*:[ \t]*//g' | fzf)
if [[ -d "${output}" ]]; then
echo -e "\\033[31m${output}\\033[0m"
cd "${output}"
else
echo -e "\\033[31m.\\033[0m"
fi
}
# an autojump-like method for "jumping" into a directory based on fzf:
# advantage: see where you are going to jump before actually jumping
ff () {
file=$(find $HOME -maxdepth 3 -type f 2> /dev/null | fzf)
[ $? -ne 0 ] && return
output=$(dirname $file)
if [[ -d "${output}" ]]; then
echo -e "\\033[31m${output}\\033[0m"
cd "${output}"
else
echo -e "\\033[31m.\\033[0m"
fi
}
# an autojump-like method for "jumping" into a directory based on fzf:
# advantage: see where you are going to jump before actually jumping
fd () {
output=$(find . -maxdepth 3 -type d 2> /dev/null | fzf)
if [[ -d "${output}" ]]; then
echo -e "\\033[31m${output}\\033[0m"
cd "${output}"
else
echo -e "\\033[31m.\\033[0m"
fi
}