59 lines
1.5 KiB
Plaintext
59 lines
1.5 KiB
Plaintext
# Utilities regarding file system navigation
|
|
|
|
# Useful when the current directory was recreated
|
|
alias rcd="cd $PWD"
|
|
# cd into the parent if arg is a file
|
|
cdd() { cd "$@" 2>/dev/null || cd "$(dirname "$1")" "${@:2}" }
|
|
|
|
# Go up a number of dirs
|
|
up() {
|
|
if [[ $# < 1 ]] ; then
|
|
cd ..
|
|
else
|
|
CDSTR=""
|
|
for i in {1..$1} ; do
|
|
CDSTR="../$CDSTR"
|
|
done
|
|
cd $CDSTR
|
|
fi
|
|
}
|
|
|
|
# Switch directory & ls
|
|
cl() {
|
|
builtin cd $1
|
|
ls --almost-all --group-directories-first --file-type
|
|
}
|
|
|
|
mkcd() {
|
|
mkdir -p "$1" && cd "$1"
|
|
}
|
|
|
|
cd() {
|
|
if test -d "$DATA" && test "$1" != "-" -a ! -d "$1" -a $# -eq 1
|
|
then
|
|
dir=$(fd --no-ignore --glob "$1*" "$DATA" --maxdepth 2 --type d --max-results 1)
|
|
test -n "$dir" && cd "$dir"
|
|
else
|
|
builtin cd $1 &&
|
|
command ls --file-type --group-directories-first --color=always --format=vertical -w $COLUMNS | head -3
|
|
fi
|
|
}
|
|
|
|
# ZOXIDE
|
|
alias c=z
|
|
d() {
|
|
test "$1" != "-" -a ! -d "$1" -a $# -eq 1 || { cd "$@" && return }
|
|
local query="$(zf "$@")"
|
|
# First find out whether there is an obvious match
|
|
# (score at least ten times above runner-up and score above 20)
|
|
# If not select with fzf, using locate to find extra options
|
|
cd "$(if expr "$(echo "$query" | head -1 | cut -d' ' -f1)" \> 20 \& $(echo "$query" | sed 'N;s|/.* \([0-9]\)|> 10 * \1|;q' | sed 's| */.*||') >/dev/null #2>&1
|
|
then echo "$query" | head -1
|
|
else echo "$query"; locz "$@"
|
|
fi | zfz)"
|
|
}
|
|
di() {
|
|
test $# -eq 1 && test "$1" = "-" -o -d "$1" || local dir=$({ zf "$@"; locz "$@" } | zfz)
|
|
cd "${dir:-$1}"
|
|
}
|