config/shell: cd alias adjustments and ordering

This commit is contained in:
xeruf 2022-03-15 17:24:43 +01:00
parent 6d9b4d5d48
commit a2ce418491
2 changed files with 39 additions and 20 deletions

View File

@ -2,8 +2,14 @@
# Useful when the current directory was recreated # Useful when the current directory was recreated
alias recd='cd $PWD' alias recd='cd $PWD'
# cd into the parent if arg is a file # [c]hange [d]irectory [e]xisting - cd into the first existing directory
cdd() { cd "$@" 2>/dev/null || cd "$(dirname "$1")" "${@:2}" } cde() {
local _dir="$1"
while ! test -d "$_dir"
do _dir="$(dirname "$_dir")"
done
cd "$_dir" "${@:2}"
}
# Go up a number of dirs # Go up a number of dirs
up() { up() {
@ -24,7 +30,7 @@ cl() {
ls --almost-all --group-directories-first --file-type ls --almost-all --group-directories-first --file-type
} }
# cd but search for data dirs and ls in new dir # cd but search for data dirs and run ls after switching to target dir
cd() { cd() {
if test -d "$DATA" && test "${1:--}" != "-" -a ! -d "$1" -a $# -eq 1 if test -d "$DATA" && test "${1:--}" != "-" -a ! -d "$1" -a $# -eq 1
then then

View File

@ -91,7 +91,8 @@ edshell() {
("") file="$CONFIG_SHELL_FUNCTIONS";; ("") file="$CONFIG_SHELL_FUNCTIONS";;
(zsh) file="$CONFIG_ZSH/.zshrc";; (zsh) file="$CONFIG_ZSH/.zshrc";;
(env) file="$HOME/.zshenv";; (env) file="$HOME/.zshenv";;
(-f) grepfile="$(grep --recursive "\(^$2()\|alias $2=\)" $CONFIG_SHELLS -n -m 1)" (-f) term=$2
grepfile="$(grep --recursive "^ *\($term()\|alias[^=]* $term=\)" $CONFIG_SHELLS -n -m 1)"
file="$(echo "$grepfile" | cut -d':' -f1)" file="$(echo "$grepfile" | cut -d':' -f1)"
line="$(echo "$grepfile" | cut -d':' -f2)" line="$(echo "$grepfile" | cut -d':' -f2)"
test -f "$file" || return 2;; test -f "$file" || return 2;;
@ -133,10 +134,13 @@ alias sc='sudo systemctl'
alias sce='sudo systemctl enable --now' alias sce='sudo systemctl enable --now'
alias scd='sudo systemctl disable --now' alias scd='sudo systemctl disable --now'
scs() { scs() {
(
export SYSTEMD_COLORS=true
systemctl --user status "$1" 2>/dev/null || systemctl --user status "$1" 2>/dev/null ||
systemctl --user status "*$1*" systemctl --user status "*$1*"
sudo systemctl status "$1" 2>/dev/null || sudo -E systemctl status "$1" 2>/dev/null ||
sudo systemctl status "*$1*" sudo -E systemctl status "*$1*"
) | less -F
} }
alias scu='systemctl --user' alias scu='systemctl --user'
alias scue='systemctl --user enable --now' alias scue='systemctl --user enable --now'
@ -186,7 +190,7 @@ alias myip="curl ifconfig.me && println && curl icanhazip.com"
alias dedup='awk '"'"'!a[$0]++'"'" alias dedup='awk '"'"'!a[$0]++'"'"
alias lar='last | tac' alias lar='last | tac'
alias lst='( last; last -f /var/log/wtmp.1 ) | grep -v "pts/" | tac | less +G' alias lst='( last; last -f /var/log/wtmp.1 ) | grep -v "pts/" | tac | less +G'
alias hedgedoc="tmux kill-session -t hedgedoc; builtin cd '$d4/dev/_forks/hedgedoc' && tmux new-session -s hedgedoc -d 'yarn run dev' && tmux split-window -h 'nodemon --watch app.js --watch lib --watch locales --watch config.json app.js' && tmux ls" alias hedgedoc="tmux kill-session -t hedgedoc; builtin cd '$d4/dev/_forks/hedgedoc' && tmux new-session -s hedgedoc -d 'yarn run dev' \; split-window -h 'nodemon --watch app.js --watch lib --watch locales --watch config.json app.js' \; ls"
alias rm='rm -I' alias rm='rm -I'
del() { del() {
@ -200,15 +204,20 @@ u() {
which pacman-mirrors >/dev/null && which pacman-mirrors >/dev/null &&
sudo pacman-mirrors --geoip && sudo pacman-mirrors --geoip &&
sudo pacman -Syy sudo pacman -Syy
topgrade topgrade &&
topgrade --only emacs --yes topgrade --only emacs --yes
# TODO autodetect failure in emacs and rebuild completely
} }
# Remote # Networking
alias dns="drill any @8.8.8.8 -Q"
alias delta="sudo systemctl restart openvpn-client@deltaPeak.service || jcl --unit openvpn-client@deltaPeak.service" alias delta="sudo systemctl restart openvpn-client@deltaPeak.service || jcl --unit openvpn-client@deltaPeak.service"
sshl() { sshl() {
lemonade server -allow 127.0.0.1 & lemonade server -allow 127.0.0.1 &
file="/var/tmp/ssh-$1" local authcache
authcache="/var/tmp/ssh-keys"
mkdir -p "$authcache"
file="$authcache/$1"
if test ! -e "$file"; then if test ! -e "$file"; then
if ! ssh -G "$1" | grep --silent "^user root$" && touch "$file"; then if ! ssh -G "$1" | grep --silent "^user root$" && touch "$file"; then
ssh-copy-id -i "$(ssh -G "$1" | grep --max-count 1 "^identityfile " | cut -d " " -f2- | sed "s|^~|$HOME|")" "$1" && touch "$file" ssh-copy-id -i "$(ssh -G "$1" | grep --max-count 1 "^identityfile " | cut -d " " -f2- | sed "s|^~|$HOME|")" "$1" && touch "$file"
@ -219,6 +228,8 @@ sshl() {
TERM=xterm-256color pass ssh "$@" TERM=xterm-256color pass ssh "$@"
} }
alias startMinecraftServer='curl https://ipinfo.io/ip | xclip -sel clip && cd ~/daten/games/sharedgames/minecraft/server && java -jar forge-1.12.2-14.23.5.2768-universal.jar -mx 8G'
# Listen to loopback of mic # Listen to loopback of mic
alias listen='pactl load-module module-loopback; echo "Press Enter to stop"; read; pactl unload-module module-loopback' alias listen='pactl load-module module-loopback; echo "Press Enter to stop"; read; pactl unload-module module-loopback'
@ -239,7 +250,7 @@ alias grpc='grep --color=auto --line-number --binary-files=without-match --direc
# Grep recursively and paginate # Grep recursively and paginate
grpr() { grp --color=always --recursive $(echo $DIRS_IGNORE | sed 's/-x/--exclude-dir/g') "$@" | less -F; } grpr() { grp --color=always --recursive $(echo $DIRS_IGNORE | sed 's/-x/--exclude-dir/g') "$@" | less -F; }
# Grep in shell config files # Grep in shell config files
grsh() { grpr --no-ignore-case "$@" $HOME/.{ba,z}sh* $HOME/.local/bin $CONFIG_SHELLS $CONFIG_ZSH } grsh() { grpr --no-ignore-case "$@" $HOME/.{ba,z}sh* $HOME/.local/bin $CONFIG_SHELLS $CONFIG_ZSH; }
# Recover stray swap files from neovim # Recover stray swap files from neovim
alias vrec="ls $XDG_DATA_HOME/nvim/swap | sed 's/\%/\//g' | sed 's|\(.*\)\..*|\1|' | head -1 | xargs --no-run-if-empty nvim" alias vrec="ls $XDG_DATA_HOME/nvim/swap | sed 's/\%/\//g' | sed 's|\(.*\)\..*|\1|' | head -1 | xargs --no-run-if-empty nvim"
@ -256,8 +267,6 @@ alias dic="cat $XDG_DATA_HOME/dictcc/dict.txt | sed '/#/d;/&/d;/^$/d' | fzf --ti
alias dict="rlwrap rdictcc -d $XDG_DATA_HOME/dictcc" alias dict="rlwrap rdictcc -d $XDG_DATA_HOME/dictcc"
alias dictu="dict -i $XDG_DATA_HOME/dictcc/dict.txt" alias dictu="dict -i $XDG_DATA_HOME/dictcc/dict.txt"
alias startMinecraftServer='curl https://ipinfo.io/ip | xclip -sel clip && cd ~/daten/games/sharedgames/minecraft/server && java -jar forge-1.12.2-14.23.5.2768-universal.jar -mx 8G'
npm-reinstall() { npm-reinstall() {
rm -rf $TMPDIR/react-* rm -rf $TMPDIR/react-*
rm -rf node_modules/ rm -rf node_modules/
@ -301,7 +310,8 @@ alias killbg='kill ${${(v)jobstates##*:*:}%=*}'
# Kill all processes that match # Kill all processes that match
killm() { killm() {
ps ax | grep "$1" | grep -v grep | sed 's/\([^ ]\) .*/\1/' | xargs kill --verbose "${@:2}" ps ax | grep "$1" | grep -v grep | sed 's/\([^ ]\) .*/\1/' |
xargs --no-run-if-empty kill --verbose "${@:2}"
} }
# Kil all Java processes except IDEA # Kil all Java processes except IDEA
@ -322,9 +332,10 @@ killJava() {
alias l="ls -l --almost-all --human-readable --group-directories-first --file-type" alias l="ls -l --almost-all --human-readable --group-directories-first --file-type"
if which fd >/dev/null if which fd >/dev/null
then alias f="noglob fdd" then alias f="noglob fn --color=always "
fdd() { $(which fd >/dev/null && echo fd || echo fdfind) --color=always --hidden --no-ignore-vcs --one-file-system "$@" | less -F; } fn() { $(which fd >/dev/null && echo fd || echo fdfind) --hidden --no-ignore-vcs --one-file-system "$@" | less -F; }
compdef f=fd compdef f=fd
compdef fn=fd
else else
alias f='find -not -path "*.sync*" -and -not \( -name daten -prune \)' alias f='find -not -path "*.sync*" -and -not \( -name daten -prune \)'
alias f1='find -mindepth 1 -maxdepth 1' alias f1='find -mindepth 1 -maxdepth 1'
@ -391,9 +402,10 @@ mkcd() {
# Other stuff {{{1 # Other stuff {{{1
umoul() { umoul() {
if test "$1" local arg
then arg="$1" for arg; do true; done
mountpoint="$(test -d "$arg" && realpath "$arg" || echo "${MNT:-${XDG_RUNTIME_DIR}/mnt}/$arg")" if test "$arg"
then mountpoint="$(test -d "$arg" && realpath "$arg" || echo "${MNT:-${XDG_RUNTIME_DIR}/mnt}/$arg")"
mountpoint "$mountpoint" 2>/dev/null || test -b "$mountpoint" || mountpoint "$mountpoint" 2>/dev/null || test -b "$mountpoint" ||
mountpoint="$(mount --show-labels | grep "$arg" | cut -d' ' -f3)" mountpoint="$(mount --show-labels | grep "$arg" | cut -d' ' -f3)"
test "$mountpoint" || return 1 test "$mountpoint" || return 1
@ -407,7 +419,8 @@ umoul() {
case "$PWD" in case "$PWD" in
("$mountpoint"*) cd "$(dirname $mountpoint)";; ("$mountpoint"*) cd "$(dirname $mountpoint)";;
esac esac
moul -u "$mountpoint" # pass on all args except last
moul -u "${@:1:$#-1}" "$mountpoint"
} }
resetdocker() { resetdocker() {