config/shell: improve directory switching shortcuts
This commit is contained in:
parent
58e1f64f8a
commit
df06bc1a09
|
@ -71,13 +71,13 @@ alias loca='noglob sudo updatedb -l 0 --prunenames "" --prunefs "tmpfs sysfs deb
|
||||||
alias c=z
|
alias c=z
|
||||||
# Listing for quick directory switcher based on zoxide and fzf
|
# Listing for quick directory switcher based on zoxide and fzf
|
||||||
alias zoxide-list='noglob zoxide query -sl'
|
alias zoxide-list='noglob zoxide query -sl'
|
||||||
# fzf for zoxide
|
__zx_ls="ls --almost-all --color --human-readable --group-directories-first --file-type"
|
||||||
|
alias fzf-dir="fzf -0 -1 --tiebreak=index \
|
||||||
|
--preview-window=30% --preview='$__zx_ls {}' \
|
||||||
|
--height=80% --reverse --keep-right"
|
||||||
|
# fzf for zoxide - returns the selected path stripped of its score
|
||||||
zoxide-fzf() {
|
zoxide-fzf() {
|
||||||
# returns the selected path stripped of its score
|
fzf-dir -n2.. --preview="$__zx_ls {2..}" "$@" | sed 's|.* /|/|'
|
||||||
fzf -0 -1 -n2.. --tiebreak=index \
|
|
||||||
--preview-window=20% --preview="ls -a --color --human-readable --group-directories-first --file-type {2..}" \
|
|
||||||
--height=80% --reverse |
|
|
||||||
sed 's|.* /|/|'
|
|
||||||
}
|
}
|
||||||
# Locate directories and add 0 zoxide score
|
# Locate directories and add 0 zoxide score
|
||||||
locate-zox() {
|
locate-zox() {
|
||||||
|
@ -92,12 +92,14 @@ d() {
|
||||||
# First find out whether there is an obvious match
|
# First find out whether there is an obvious match
|
||||||
# (score at least ten times above runner-up and score above 20)
|
# (score at least ten times above runner-up and score above 20)
|
||||||
# If not select with fzf, using locate to find extra options
|
# If not select with fzf, using locate to find extra options
|
||||||
cd "$(if test -n "$query" &&
|
target="$(if test -n "$query" &&
|
||||||
expr "$(echo "$query" | sed 's| \+\([^ ]\+\).*|\1|;q')" \> 20 \& \
|
expr "$(echo "$query" | sed 's| \+\([^ ]\+\).*|\1|;q')" \> 20 \& \
|
||||||
$(echo "$query" | sed 'N;s|/.* \([0-9]\)|> 10 * \1|;q' | sed 's| */.*||') >/dev/null #2>&1
|
$(echo "$query" | sed 'N;s|/.* \([0-9]\)|> 10 * \1|;q' | sed 's| */.*||') >/dev/null #2>&1
|
||||||
then echo "$query" | head -1
|
then echo "$query" | head -1
|
||||||
else test -n "$query" && echo "$query"; locate-zox "$@"
|
else test -n "$query" && echo "$query"; locate-zox "$@"
|
||||||
fi | zoxide-fzf)"
|
fi | zoxide-fzf)" &&
|
||||||
|
test -z "$target" && sudo updatedb && target="$(locate --basename "$@" | fzf-dir)"
|
||||||
|
test -n "$target" && cd "$target"
|
||||||
}
|
}
|
||||||
# Switch directory interactively using zoxide and locate
|
# Switch directory interactively using zoxide and locate
|
||||||
di() {
|
di() {
|
||||||
|
|
|
@ -37,7 +37,6 @@ if test -d "$DATA"; then
|
||||||
d3=$(builtin cd $DATA/3* && pwd)
|
d3=$(builtin cd $DATA/3* && pwd)
|
||||||
d4=$(builtin cd $DATA/4* && pwd)
|
d4=$(builtin cd $DATA/4* && pwd)
|
||||||
d5=$(builtin cd $DATA/5* && pwd)
|
d5=$(builtin cd $DATA/5* && pwd)
|
||||||
dd="$d5/downloads"
|
|
||||||
fi 2>/dev/null
|
fi 2>/dev/null
|
||||||
|
|
||||||
ulimit -c unlimited # Enable core dumps
|
ulimit -c unlimited # Enable core dumps
|
||||||
|
@ -68,7 +67,7 @@ wh() {
|
||||||
res=$(which "$@")
|
res=$(which "$@")
|
||||||
if expr "$res" : "${@:$#}: aliased to" >/dev/null && ! expr "$res" : ".*builtin" >/dev/null
|
if expr "$res" : "${@:$#}: aliased to" >/dev/null && ! expr "$res" : ".*builtin" >/dev/null
|
||||||
then echo "$res" | bat --style=plain --language=sh &&
|
then echo "$res" | bat --style=plain --language=sh &&
|
||||||
tool="$(echo "$res" | cut -d' ' -f$(expr 5 '&' "$res" : ".*to \(sudo\|noglob\) " '|' 4) | cut -d'(' -f2)"
|
tool="$(echo "$res" | head -1 | cut -d' ' -f$(expr 5 '&' "$res" : ".*to \(sudo\|noglob\) " '|' 4) | cut -d'(' -f2)"
|
||||||
wh $(test $tool = $1 && echo "-p") $tool
|
wh $(test $tool = $1 && echo "-p") $tool
|
||||||
# use command which for other shells
|
# use command which for other shells
|
||||||
else test -r "$res" && b "$res" || echo "$res" | bat --style=plain --language=sh
|
else test -r "$res" && b "$res" || echo "$res" | bat --style=plain --language=sh
|
||||||
|
|
Loading…
Reference in New Issue