config/shell: reorder shell configuration
This commit is contained in:
parent
097634013a
commit
3330b7ff80
|
@ -0,0 +1,55 @@
|
||||||
|
# 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() {
|
||||||
|
test "$1" != "-" -a ! -d "$1" -a $# -eq 1 &&
|
||||||
|
dir=$(f --glob "$1*" "$DATA" --maxdepth 2 --type d --max-results 1) &&
|
||||||
|
test -n "$dir" && cd "$dir" && return
|
||||||
|
builtin cd $1 &&
|
||||||
|
command ls --file-type --group-directories-first --color=always --format=vertical -w $COLUMNS | head -3
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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' ' -f2)" \> 20 \& $(echo "$query" | sed 'N;s|/.*\n|> 10 *|;q' | sed 's| */.*||') >/dev/null 2>&1
|
||||||
|
then echo "$query" | head -1
|
||||||
|
else echo "$query"; locz "$@"
|
||||||
|
fi | zfz)"
|
||||||
|
}
|
||||||
|
di() {
|
||||||
|
test "$1" != "-" -a ! -d "$1" -a $# -eq 1 && local dir=$({ zf "$@"; locz "$@" } | zfz)
|
||||||
|
cd "${dir:-1}"
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
# Shell aliases & functions for Zsh, works almost completely for Bash as well
|
# Shell aliases & functions for Zsh, almost all work for Bash too
|
||||||
|
# data directory aliases {{{1
|
||||||
if test "$ZSH_NAME" = "zsh"; then
|
if test "$ZSH_NAME" = "zsh"; then
|
||||||
alias -g ___='"$(eval "$(fc -ln -1)" | tail -n 1)"'
|
alias -g ___='"$(eval "$(fc -ln -1)" | tail -n 1)"'
|
||||||
alias -g G="| grp"
|
alias -g G="| grp"
|
||||||
|
@ -9,29 +9,6 @@ alias -g XC="| xclip -selection clipboard"
|
||||||
alias -g L="--color=always | ${PAGER:-less}"
|
alias -g L="--color=always | ${PAGER:-less}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
alias h='help'
|
|
||||||
compdef help=man
|
|
||||||
alias info='info --vi-keys'
|
|
||||||
|
|
||||||
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' ' -f2)" \> 20 \& $(echo "$query" | sed 'N;s|/.*\n|> 10 *|;q' | sed 's| */.*||') >/dev/null 2>&1
|
|
||||||
then echo "$query" | head -1
|
|
||||||
else echo "$query"; locz "$@"
|
|
||||||
fi | zfz)"
|
|
||||||
}
|
|
||||||
di() {
|
|
||||||
test "$1" != "-" -a ! -d "$1" -a $# -eq 1 && local dir=$({ zf "$@"; locz "$@" } | zfz)
|
|
||||||
cd "${dir:-1}"
|
|
||||||
}
|
|
||||||
alias c=z
|
|
||||||
alias v=edit
|
|
||||||
alias hx='sudo hexedit --maximize --color'
|
|
||||||
|
|
||||||
xdh="$XDG_DATA_HOME"
|
xdh="$XDG_DATA_HOME"
|
||||||
xch="$XDG_CONFIG_HOME"
|
xch="$XDG_CONFIG_HOME"
|
||||||
if test -d "$DATA"; then
|
if test -d "$DATA"; then
|
||||||
|
@ -48,8 +25,18 @@ which lsb_release >/dev/null && export DIST=$(lsb_release --id | cut -d' ' -f2)
|
||||||
|
|
||||||
unalias rd 2>/dev/null
|
unalias rd 2>/dev/null
|
||||||
|
|
||||||
# like "which", but shows contents if it resolves to a file
|
# Basic aliases {{{1
|
||||||
# and resolves recursive aliases
|
|
||||||
|
alias h='help'
|
||||||
|
compdef help=man
|
||||||
|
alias info='info --vi-keys'
|
||||||
|
|
||||||
|
alias v=edit
|
||||||
|
|
||||||
|
alias println='printf "\n"'
|
||||||
|
alias dedup='awk '"'"'!a[$0]++'"'"
|
||||||
|
|
||||||
|
# Shows source code for command, resolving nested aliases
|
||||||
wh() {
|
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
|
||||||
|
@ -61,44 +48,38 @@ wh() {
|
||||||
}
|
}
|
||||||
compdef wh=which
|
compdef wh=which
|
||||||
|
|
||||||
alias calc='rlwrap -a bc -l'
|
# Some configuration aliases that include sane verification
|
||||||
alias logoff="loginctl terminate-user $USER"
|
|
||||||
blues() { bluedevil-sendfile $(echo "$@" | xargs -n 1 realpath | xargs -n 1 echo -n " --files") }
|
|
||||||
|
|
||||||
alias u='topgrade'
|
|
||||||
|
|
||||||
alias j='jrnl'
|
|
||||||
jn() { jrnl -to today "$@" | bat --style=plain --pager="less +G" }
|
|
||||||
compdef jn=jrnl
|
|
||||||
alias jnc='jn -contains'
|
|
||||||
|
|
||||||
# Some aliases
|
|
||||||
alias edgrub='sudoedit /etc/default/grub && sudo update-grub'
|
alias edgrub='sudoedit /etc/default/grub && sudo update-grub'
|
||||||
alias edenv='sudoedit /etc/environment'
|
|
||||||
alias edpart='sudoedit /etc/fstab && sudo findmnt --verify'
|
alias edpart='sudoedit /etc/fstab && sudo findmnt --verify'
|
||||||
|
alias edenv='sudoedit /etc/environment'
|
||||||
alias dedup='awk '"'"'!a[$0]++'"'"
|
pathadd() {
|
||||||
listconf() {
|
local IFS=":"
|
||||||
{ cat "$conf_cache"; test -f "$conf_extra" && cat "$conf_extra";
|
local result="$@"
|
||||||
fd --hidden --type file --size -1m --max-depth 1 . ~;
|
unset IFS
|
||||||
sudo find "$XDG_CONFIG_HOME" /etc -maxdepth 3 -type f -exec grep -lI '' {} + } | dedup
|
cat /etc/environment | head -1 | cut -d'"' -f2 | tr ":" "\n" | while read v
|
||||||
|
do [[ " $@ " =~ " $v " ]] || result+=":$v"
|
||||||
|
done
|
||||||
|
echo PATH=\"${result}\"\\n$(cat /etc/environment | tail -n +2) | sudo tee /etc/environment
|
||||||
}
|
}
|
||||||
|
|
||||||
edconf() {
|
# ZSH completion and stuff {{{1
|
||||||
conf_cache_dir="$XDG_CACHE_HOME/edconf"
|
|
||||||
conf_cache="$conf_cache_dir/files"
|
|
||||||
conf_tmp="${conf_cache}.tmp"
|
|
||||||
conf_extra="$XDG_CONFIG_HOME/edconf-extra"
|
|
||||||
mkdir -p "$conf_cache_dir"
|
|
||||||
touch "$conf_cache"
|
|
||||||
sel=$(listconf | fzf -1 -0 --tiebreak=end,length --preview '$(test -r "{}" || echo "sudo") bat --color=always --style=numbers --line-range :200 {}' --query="$1" --history "$conf_cache_dir/searches")
|
|
||||||
test "$sel" && ((echo "$sel" | cat - "$conf_cache" | head -20 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache") & edit "$sel")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
alias rs="reset && exec $SHELL"
|
||||||
alias hist='print -z $(history | tac | fzf --tiebreak=index --bind="'"del:execute(echo \"'/;{4..}$/d'\" && sed '/;{4..}$/d' -i.bak $HISTFILE)"'" | sed "s|^ \+||" | cut -d" " -f5-)'
|
alias hist='print -z $(history | tac | fzf --tiebreak=index --bind="'"del:execute(echo \"'/;{4..}$/d'\" && sed '/;{4..}$/d' -i.bak $HISTFILE)"'" | sed "s|^ \+||" | cut -d" " -f5-)'
|
||||||
|
|
||||||
CONFIG_SHELL_FUNCTIONS="${BASH_SOURCE[0]:-${(%):-%x}}"
|
CONFIG_SHELL_FUNCTIONS="${BASH_SOURCE[0]:-${(%):-%x}}"
|
||||||
alias rs="reset && exec zsh"
|
edshell() {
|
||||||
|
case $1 in
|
||||||
|
("") file="$CONFIG_SHELL_FUNCTIONS";;
|
||||||
|
(zsh) file="$CONFIG_ZSH/.zshrc";;
|
||||||
|
(prof*) file="$HOME/.zprofile";;
|
||||||
|
(*) file=$(find $CONFIG_SHELLS -name "$1*" | head -1 | grep . || echo "$CONFIG_SHELLS/$1");;
|
||||||
|
esac
|
||||||
|
checksum="$(md5sum "$file")"
|
||||||
|
$EDITOR "$file"
|
||||||
|
test "$checksum" != "$(md5sum $file)" && source "$HOME/.zprofile" && exec $SHELL
|
||||||
|
}
|
||||||
|
|
||||||
edcomp() {
|
edcomp() {
|
||||||
file=$(echo "$1" | sed 's/^\([^_]\)/_\1/')
|
file=$(echo "$1" | sed 's/^\([^_]\)/_\1/')
|
||||||
$EDITOR "${fpath[-1]}/$file"
|
$EDITOR "${fpath[-1]}/$file"
|
||||||
|
@ -106,38 +87,12 @@ edcomp() {
|
||||||
}
|
}
|
||||||
compdef "_files -W ${fpath[-1]}/" edcomp
|
compdef "_files -W ${fpath[-1]}/" edcomp
|
||||||
|
|
||||||
edshell() {
|
writecompletion() {
|
||||||
case $1 in
|
echo "#compdef $1" > "_$1"
|
||||||
("") file="$CONFIG_SHELL_FUNCTIONS";;
|
$EDITOR "_$1"
|
||||||
(zsh) file="$CONFIG_ZSH/.zshrc";;
|
|
||||||
(prof*) file="$HOME/.zprofile";;
|
|
||||||
(*) file=$(find $CONFIG_SHELLS -name "$1*" | head -1);;
|
|
||||||
esac
|
|
||||||
checksum="$(md5sum $file)"
|
|
||||||
$EDITOR $file
|
|
||||||
test "$checksum" != "$(md5sum $file)" && source "$HOME/.zprofile" && exec $SHELL
|
|
||||||
}
|
}
|
||||||
|
|
||||||
alias l="ls -l --almost-all --human-readable --group-directories-first --file-type"
|
# Task management & time tracking {{{1
|
||||||
cd() {
|
|
||||||
test "$1" != "-" -a ! -d "$1" -a $# -eq 1 &&
|
|
||||||
dir=$(f --glob "$1*" "$DATA" --maxdepth 2 --type d --max-results 1) &&
|
|
||||||
test -n "$dir" && cd "$dir" && return
|
|
||||||
builtin cd $1 &&
|
|
||||||
command ls --file-type --group-directories-first --color=always --format=vertical -w $COLUMNS | head -3
|
|
||||||
}
|
|
||||||
|
|
||||||
swap() {
|
|
||||||
mv -n $1 $1.tmp
|
|
||||||
mv -n $2 $1
|
|
||||||
mv -n $1.tmp $2
|
|
||||||
}
|
|
||||||
|
|
||||||
p() {
|
|
||||||
pass "$@" || pass edit "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Task management & time tracking
|
|
||||||
t() {
|
t() {
|
||||||
if test "$#" -eq 0 && which tn >/dev/null
|
if test "$#" -eq 0 && which tn >/dev/null
|
||||||
then tn
|
then tn
|
||||||
|
@ -152,32 +107,9 @@ alias tw='timew'
|
||||||
# Create a temporary timewarrior database for testing
|
# Create a temporary timewarrior database for testing
|
||||||
alias twtest='( cp -r "$TIMEWARRIORDB" /tmp/tw-bak && TIMEWARRIORDB=/tmp/timewarriordb-test/$(date +%s) && mkdir -p "$TIMEWARRIORDB"/data && :> "$TIMEWARRIORDB"/timewarrior.cfg && $SHELL )'
|
alias twtest='( cp -r "$TIMEWARRIORDB" /tmp/tw-bak && TIMEWARRIORDB=/tmp/timewarriordb-test/$(date +%s) && mkdir -p "$TIMEWARRIORDB"/data && :> "$TIMEWARRIORDB"/timewarrior.cfg && $SHELL )'
|
||||||
|
|
||||||
alias expr='noglob expr'
|
# Systemd {{{1
|
||||||
alias lst='( last; last -f /var/log/wtmp.1 ) | grep -v "pts/" | tac | less +G'
|
|
||||||
alias lar='last | tac'
|
|
||||||
|
|
||||||
# Listen to loopback of mic
|
|
||||||
alias listen='pactl load-module module-loopback; echo "Press Enter to stop"; read; pactl unload-module module-loopback'
|
|
||||||
|
|
||||||
xo() {
|
|
||||||
while test $# -gt 0; do
|
|
||||||
xdg-open "$1"
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
}
|
|
||||||
alias sqli='rlwrap sqlite3 -column -header -cmd .tables'
|
|
||||||
loci() { locate --all --ignore-case --basename --existing "$@" | command grep --extended-regexp --ignore-case --color=always $(echo "$|$@" | sed 's/ /|/g') | less -F }
|
|
||||||
alias loc='noglob loci'
|
|
||||||
alias uloc='noglob sudo updatedb && loci'
|
|
||||||
alias syslog='less +F /var/log/syslog'
|
alias syslog='less +F /var/log/syslog'
|
||||||
alias println='printf "\n"'
|
|
||||||
alias graphics='lspci -vnn | grep VGA --color=never && xrandr --listproviders'
|
|
||||||
alias usergroups="cat /etc/passwd | cut -d':' -f1 | xargs -n 1 id"
|
|
||||||
alias omd="(echo '#+OPTIONS: tags:nil'; xclip -o -selection clipboard) | pandoc -f org-auto_identifiers -t markdown --wrap preserve | xclip -filter"
|
|
||||||
alias mdo="pandoc -f gfm-ascii_identifiers-gfm_auto_identifiers -t org --wrap preserve"
|
|
||||||
alias mdox="xclip -o -selection clipboard | mdo | xclip -filter"
|
|
||||||
|
|
||||||
alias gdiff='git diff --word-diff=color --word-diff-regex=. --no-index'
|
|
||||||
|
|
||||||
alias sc='sudo systemctl'
|
alias sc='sudo systemctl'
|
||||||
alias sce='sudo systemctl enable --now'
|
alias sce='sudo systemctl enable --now'
|
||||||
|
@ -200,6 +132,36 @@ alias jcl='sudo SYSTEMD_LESS=FRKi journalctl --boot --no-hostname -e'
|
||||||
alias jc='jcl -u'
|
alias jc='jcl -u'
|
||||||
alias jcj='jcl -o json-pretty -u'
|
alias jcj='jcl -o json-pretty -u'
|
||||||
|
|
||||||
|
# Applications {{{1
|
||||||
|
|
||||||
|
alias calc='rlwrap -a bc -l'
|
||||||
|
alias logoff="loginctl terminate-user $USER"
|
||||||
|
blues() { bluedevil-sendfile $(echo "$@" | xargs -n 1 realpath | xargs -n 1 echo -n " --files") }
|
||||||
|
|
||||||
|
loci() { locate --all --ignore-case --basename --existing "$@" | command grep --extended-regexp --ignore-case --color=always $(echo "$|$@" | sed 's/ /|/g') | less -F }
|
||||||
|
alias loc='noglob loci'
|
||||||
|
alias uloc='noglob sudo updatedb && loci'
|
||||||
|
|
||||||
|
alias expr='noglob expr'
|
||||||
|
|
||||||
|
alias lst='( last; last -f /var/log/wtmp.1 ) | grep -v "pts/" | tac | less +G'
|
||||||
|
alias lar='last | tac'
|
||||||
|
|
||||||
|
# Listen to loopback of mic
|
||||||
|
alias listen='pactl load-module module-loopback; echo "Press Enter to stop"; read; pactl unload-module module-loopback'
|
||||||
|
|
||||||
|
alias sqli='rlwrap sqlite3 -column -header -cmd .tables'
|
||||||
|
|
||||||
|
alias usergroups="cat /etc/passwd | cut -d':' -f1 | xargs -n 1 id"
|
||||||
|
|
||||||
|
p() { pass "$@" || pass edit "$@"; }
|
||||||
|
|
||||||
|
alias omd="(echo '#+OPTIONS: tags:nil'; xclip -o -selection clipboard) | pandoc -f org-auto_identifiers -t markdown --wrap preserve | xclip -filter"
|
||||||
|
alias mdo="pandoc -f gfm-ascii_identifiers-gfm_auto_identifiers -t org --wrap preserve"
|
||||||
|
alias mdox="xclip -o -selection clipboard | mdo | xclip -filter"
|
||||||
|
|
||||||
|
alias gdiff='git diff --word-diff=color --word-diff-regex=. --no-index'
|
||||||
|
|
||||||
alias grp='grep --color=auto --line-number --ignore-case --binary-files=without-match --directories=skip'
|
alias grp='grep --color=auto --line-number --ignore-case --binary-files=without-match --directories=skip'
|
||||||
grpr() { grp --color=always --recursive $(echo $IGNOREDIRS | sed 's/-x/--exclude-dir/g') "$@" | less -F }
|
grpr() { grp --color=always --recursive $(echo $IGNOREDIRS | sed 's/-x/--exclude-dir/g') "$@" | less -F }
|
||||||
|
|
||||||
|
@ -207,21 +169,33 @@ grpr() { grp --color=always --recursive $(echo $IGNOREDIRS | sed 's/-x/--exclude
|
||||||
alias vrec="ls $XDG_DATA_HOME/nvim/swap | sed 's/\%/\//g' | sed 's|\(.*\)\..*|\1|' | head -1 | xargs -r nvim"
|
alias vrec="ls $XDG_DATA_HOME/nvim/swap | sed 's/\%/\//g' | sed 's|\(.*\)\..*|\1|' | head -1 | xargs -r nvim"
|
||||||
alias vrecd="ls $XDG_DATA_HOME/nvim/swap | head -1 | xargs -r -i mv {} /tmp"
|
alias vrecd="ls $XDG_DATA_HOME/nvim/swap | head -1 | xargs -r -i mv {} /tmp"
|
||||||
|
|
||||||
|
# I think this was something about recovering backup files
|
||||||
unv() { strings $1 | sed 's/5$//' | dedup }
|
unv() { strings $1 | sed 's/5$//' | dedup }
|
||||||
|
|
||||||
|
alias hx='sudo hexedit --maximize --color'
|
||||||
|
# Paginated hexyl
|
||||||
hex() { hexyl "$@" | "${PAGER:-less}" }
|
hex() { hexyl "$@" | "${PAGER:-less}" }
|
||||||
|
|
||||||
# Applications
|
alias dict="rdictcc -d $XDG_DATA_HOME/dictcc"
|
||||||
alias dict="rdictcc -d $XDG_DATA_HOME/dictcc" #"(builtin cd $XDG_DATA_HOME/dictcc && rlwrap perl dictcc-helper.pl)"
|
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'
|
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'
|
||||||
alias delta="sc start openvpn-client@deltaPeak.service"
|
alias delta="sc start openvpn-client@deltaPeak.service"
|
||||||
|
|
||||||
test -d $HOME/.dropbox && dropbox_path="$(cat $HOME/.dropbox/info.json | grep -Po '"'"path"'"\s*:\s*"\K([^"]*)')"
|
alias u='topgrade'
|
||||||
|
|
||||||
# Add an "alert" alias for long running commands. Use like so: sleep 10; alert
|
alias j='jrnl'
|
||||||
#if [ command -v notify-send >/dev/null 2>&1 ]; then
|
jn() { jrnl -to today "$@" | bat --style=plain --pager="less +G" }
|
||||||
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(echo "$history[$HISTCMD]" | sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
|
compdef jn=jrnl
|
||||||
#fi
|
alias jnc='jn -contains'
|
||||||
|
|
||||||
|
npm-reinstall() {
|
||||||
|
rm -rf $TMPDIR/react-*
|
||||||
|
rm -rf node_modules/
|
||||||
|
npm cache verify
|
||||||
|
npm install
|
||||||
|
}
|
||||||
|
|
||||||
|
# Custom tools {{{1
|
||||||
|
|
||||||
sedcomment() { sed -i 's/$1/#\0/' "${@:2}" }
|
sedcomment() { sed -i 's/$1/#\0/' "${@:2}" }
|
||||||
seduncomment() { sed -i 's/#\($1\)/\0/' "${@:2}" }
|
seduncomment() { sed -i 's/#\($1\)/\0/' "${@:2}" }
|
||||||
|
@ -268,38 +242,18 @@ killJava() {
|
||||||
fi; done
|
fi; done
|
||||||
}
|
}
|
||||||
|
|
||||||
clearNpmCache() {
|
# Files {{{1
|
||||||
rm -rf $TMPDIR/react-*
|
|
||||||
rm -rf node_modules/
|
alias l="ls -l --almost-all --human-readable --group-directories-first --file-type"
|
||||||
npm cache verify
|
|
||||||
npm install
|
# Swap the names of two files
|
||||||
|
swap() {
|
||||||
|
test $# -eq 2 || exit 1
|
||||||
|
mv -n $1 $1.tmp
|
||||||
|
mv -n $2 $1
|
||||||
|
mv -n $1.tmp $2
|
||||||
}
|
}
|
||||||
|
|
||||||
# NAVIGATION
|
|
||||||
|
|
||||||
alias rcd="cd $PWD"
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
# FILES
|
|
||||||
|
|
||||||
alias f="noglob $(which fd >/dev/null && echo fd || echo fdfind) --hidden --no-ignore-vcs --one-file-system"
|
alias f="noglob $(which fd >/dev/null && echo fd || echo fdfind) --hidden --no-ignore-vcs --one-file-system"
|
||||||
#alias f='find -not -path "*.sync*" -and -not \( -name daten -prune \)'
|
#alias f='find -not -path "*.sync*" -and -not \( -name daten -prune \)'
|
||||||
|
@ -308,10 +262,6 @@ alias f="noglob $(which fd >/dev/null && echo fd || echo fdfind) --hidden --no-i
|
||||||
lowercase_transliterate="y/A-Z /a-z-/"
|
lowercase_transliterate="y/A-Z /a-z-/"
|
||||||
which perl-rename >/dev/null && alias lowercase="perl-rename '$lowercase_transliterate'" || alias lowercase="rename '$lowercase_transliterate'"
|
which perl-rename >/dev/null && alias lowercase="perl-rename '$lowercase_transliterate'" || alias lowercase="rename '$lowercase_transliterate'"
|
||||||
|
|
||||||
mkcd() {
|
|
||||||
mkdir -p "$1" && cd "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
alias move='rsync --recursive --progress --human-readable --remove-source-files'
|
alias move='rsync --recursive --progress --human-readable --remove-source-files'
|
||||||
alias rdiff='rsync --recursive --progress --delete --links --dry-run'
|
alias rdiff='rsync --recursive --progress --delete --links --dry-run'
|
||||||
|
|
||||||
|
@ -338,22 +288,7 @@ mvln() {
|
||||||
ln -vsr "$2" "$1"
|
ln -vsr "$2" "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
# OTHER
|
# Other stuff {{{1
|
||||||
|
|
||||||
pathadd() {
|
|
||||||
local IFS=":"
|
|
||||||
local result="$@"
|
|
||||||
unset IFS
|
|
||||||
cat /etc/environment | head -1 | cut -d'"' -f2 | tr ":" "\n" | while read v
|
|
||||||
do [[ " $@ " =~ " $v " ]] || result+=":$v"
|
|
||||||
done
|
|
||||||
echo PATH=\"${result}\"\\n$(cat /etc/environment | tail -n +2) | sudo tee /etc/environment
|
|
||||||
}
|
|
||||||
|
|
||||||
writecompletion() {
|
|
||||||
echo "#compdef $1" > "_$1"
|
|
||||||
$EDITOR "_$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
resetdocker() {
|
resetdocker() {
|
||||||
#aptremove docker-ce
|
#aptremove docker-ce
|
||||||
|
@ -363,71 +298,6 @@ resetdocker() {
|
||||||
#aptinstall docker-ce
|
#aptinstall docker-ce
|
||||||
}
|
}
|
||||||
|
|
||||||
# RANDOM
|
|
||||||
|
|
||||||
typeset -A _clean_map
|
|
||||||
if test "$BASH_VERSION"
|
|
||||||
then _clean_map=([h]=$XDG_CACHE_HOME [t]=/var/tmp)
|
|
||||||
else _clean_map=(h $XDG_CACHE_HOME t /var/tmp v /var/cache)
|
|
||||||
fi
|
|
||||||
_clean_folders=()
|
|
||||||
clean() {
|
|
||||||
for f in $_clean_folders
|
|
||||||
do test -d $f && rm -rv $f
|
|
||||||
done
|
|
||||||
|
|
||||||
highlight "g to clean gradle"
|
|
||||||
if [[ $1 =~ "g" ]]; then
|
|
||||||
find ${GRADLE_USER_HOME:-$HOME/.gradle} -mindepth 1 -maxdepth 1 -type d -print -exec rm -r {} +
|
|
||||||
find $projects_dir -name .gradle -print -exec rm -r {} +
|
|
||||||
fi
|
|
||||||
|
|
||||||
highlight "e to clean electron caches"
|
|
||||||
[[ $1 =~ "e" ]] && find "$XDG_CONFIG_HOME" -type d -name "*Cache" -exec rm -r {} + -prune
|
|
||||||
|
|
||||||
if test "$BASH_VERSION"; then
|
|
||||||
for k in "${!_clean_map[@]}"; do
|
|
||||||
highlight "$k to delete $_clean_map[$k]"
|
|
||||||
echo "key : $k"
|
|
||||||
echo "value: ${_clean_map[$k]}"
|
|
||||||
done
|
|
||||||
else
|
|
||||||
for k in "${(@k)_clean_map}"; do
|
|
||||||
folder=$_clean_map[$k]
|
|
||||||
highlight "$k to delete $folder"
|
|
||||||
[[ $1 =~ "$k" ]] && sudo rm -rf "$folder" && echo "Deleted $folder"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test -f "/var/log/apt/history.log"; then
|
|
||||||
aptclean_cur=$(cat "/var/log/apt/history.log" | wc -l)
|
|
||||||
test "$aptclean_cur" -gt "$aptclean_last" && aptclean && echo "Cleaned apt"
|
|
||||||
export aptclean_last=$aptclean_cur
|
|
||||||
fi
|
|
||||||
|
|
||||||
highlight "c to recursively remove development caches"
|
|
||||||
if [[ $1 =~ "c" ]]; then
|
|
||||||
find -name ".gradle" -o -name "generated" -o -name "dist_newstyle" -o -name "cache" -o -name "node_modules" -print -exec rm -r {} + -prune
|
|
||||||
find -name "*build" -print -exec rm -rI {} + -prune
|
|
||||||
fi
|
|
||||||
|
|
||||||
highlight "m to recursively remove mac-files"
|
|
||||||
if [[ $1 =~ "m" ]]; then
|
|
||||||
find -iname '.spotlight*' -exec rm -rI {} +
|
|
||||||
find -name '*.DS_Store' -delete
|
|
||||||
fi
|
|
||||||
|
|
||||||
highlight "f to recursively remove empty folders"
|
|
||||||
[[ $1 =~ "f" ]] && find -empty -type d -delete -print
|
|
||||||
|
|
||||||
highlight "o to optimize extensively"
|
|
||||||
if [[ $1 =~ "o" ]]; then
|
|
||||||
which yay &>/dev/null && yay -Sc --noconfirm
|
|
||||||
nix-collect-garbage -d
|
|
||||||
nix-store --optimize
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function zipdiff() {
|
function zipdiff() {
|
||||||
diff -W200 -y <(unzip -vql $1 | sort -k8) <(unzip -vql $2 | sort -k8) #--suppress-common-lines
|
diff -W200 -y <(unzip -vql $1 | sort -k8) <(unzip -vql $2 | sort -k8) #--suppress-common-lines
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,19 @@
|
||||||
|
# Pop up a message, for long running commands
|
||||||
|
command -v notify-send >/dev/null &&
|
||||||
|
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(echo "$history[$HISTCMD]" | sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
|
||||||
|
|
||||||
|
xo() {
|
||||||
|
while test $# -gt 0; do
|
||||||
|
xdg-open "$1"
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
test "$DISPLAY" || return 0
|
test "$DISPLAY" || return 0
|
||||||
|
|
||||||
|
alias graphics='lspci -vnn | grep VGA --color=never && xrandr --listproviders'
|
||||||
|
|
||||||
|
# WIP Edit mozilla config
|
||||||
mozedit() (
|
mozedit() (
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
file="$1"
|
file="$1"
|
||||||
|
@ -14,9 +28,10 @@ mozedit() (
|
||||||
|
|
||||||
test "$XDG_CURRENT_DESKTOP" = "KDE" || return 0
|
test "$XDG_CURRENT_DESKTOP" = "KDE" || return 0
|
||||||
|
|
||||||
# Fix broken mime messages
|
# Fix errors regarding broken mim database
|
||||||
alias fixmime='sudo rm /usr/share/mime/packages/kde.xml && sudo update-mime-database /usr/share/mime'
|
alias fixmime='sudo rm /usr/share/mime/packages/kde.xml && sudo update-mime-database /usr/share/mime'
|
||||||
|
|
||||||
|
# Switch theme across KDE system and taskwarrior
|
||||||
theme_save="$XDG_CACHE_HOME/theme"
|
theme_save="$XDG_CACHE_HOME/theme"
|
||||||
#theme_default="$(d=$(date +%H) && test $d -gt 7 && test $d -lt 19 && echo light || echo dark)"
|
#theme_default="$(d=$(date +%H) && test $d -gt 7 && test $d -lt 19 && echo light || echo dark)"
|
||||||
theme_default="dark"
|
theme_default="dark"
|
||||||
|
|
|
@ -7,9 +7,8 @@ set -eo pipefail
|
||||||
for last; do true; done
|
for last; do true; done
|
||||||
last=${last:-.}
|
last=${last:-.}
|
||||||
|
|
||||||
# Elevate permissions if the file exists but is not readable
|
# Elevate permissions if the file exists but is not accessible
|
||||||
# TODO: find the first visible directory up the tree and check if that is accessible
|
test -r "$(dirname $last)" || elevate=sudo
|
||||||
test -e "$last" || test -e "$(dirname $last)" && { test -r "$last" || elevate=sudo; }
|
|
||||||
tput setaf 4 && $elevate file -E "$last" | ( grep -v --color=never 'directory$' || true )
|
tput setaf 4 && $elevate file -E "$last" | ( grep -v --color=never 'directory$' || true )
|
||||||
|
|
||||||
case "$($elevate file --dereference --mime "$last")" in
|
case "$($elevate file --dereference --mime "$last")" in
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Cleans up files according to given parameters
|
||||||
|
|
||||||
|
typeset -A _clean_map
|
||||||
|
_clean_map=([h]=$XDG_CACHE_HOME [t]=/var/tmp)
|
||||||
|
# Directories to always clean
|
||||||
|
_clean_folders=()
|
||||||
|
|
||||||
|
for f in $_clean_folders
|
||||||
|
do test -d $f && rm -rv $f
|
||||||
|
done
|
||||||
|
|
||||||
|
highlight "g to clean gradle"
|
||||||
|
if [[ $1 =~ "g" ]]; then
|
||||||
|
find ${GRADLE_USER_HOME:-$HOME/.gradle} -mindepth 1 -maxdepth 1 -type d -print -exec rm -r {} +
|
||||||
|
find $projects_dir -name .gradle -print -exec rm -r {} +
|
||||||
|
fi
|
||||||
|
|
||||||
|
highlight "e to clean electron caches"
|
||||||
|
[[ $1 =~ "e" ]] && find "$XDG_CONFIG_HOME" -type d -name "*Cache" -exec rm -r {} + -prune
|
||||||
|
|
||||||
|
for k in "${!_clean_map[@]}"; do
|
||||||
|
folder="${_clean_map[$k]}"
|
||||||
|
highlight "$k to delete $folder"
|
||||||
|
[[ $1 =~ "$k" ]] && sudo rm -rf "$folder" && echo "Deleted $folder"
|
||||||
|
done
|
||||||
|
|
||||||
|
if test -f "/var/log/apt/history.log"; then
|
||||||
|
aptclean_cur=$(cat "/var/log/apt/history.log" | wc -l)
|
||||||
|
test "$aptclean_cur" -gt "$aptclean_last" && aptclean && echo "Cleaned apt"
|
||||||
|
export aptclean_last=$aptclean_cur
|
||||||
|
fi
|
||||||
|
|
||||||
|
highlight "c to recursively remove development caches"
|
||||||
|
if [[ $1 =~ "c" ]]; then
|
||||||
|
find -name ".gradle" -o -name "generated" -o -name "dist_newstyle" -o -name "cache" -o -name "node_modules" -print -exec rm -r {} + -prune
|
||||||
|
find -name "*build" -print -exec rm -rI {} + -prune
|
||||||
|
fi
|
||||||
|
|
||||||
|
highlight "m to recursively remove mac-files"
|
||||||
|
if [[ $1 =~ "m" ]]; then
|
||||||
|
find -iname '.spotlight*' -exec rm -rI {} +
|
||||||
|
find -name '*.DS_Store' -delete
|
||||||
|
fi
|
||||||
|
|
||||||
|
highlight "f to recursively remove empty folders"
|
||||||
|
[[ $1 =~ "f" ]] && find -empty -type d -delete -print
|
||||||
|
|
||||||
|
highlight "o to optimize space extensively"
|
||||||
|
if [[ $1 =~ "o" ]]; then
|
||||||
|
which yay &>/dev/null && yay -Sc --noconfirm
|
||||||
|
nix-collect-garbage -d
|
||||||
|
nix-store --optimize
|
||||||
|
fi
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Find and edit config files utilizing fzf
|
||||||
|
listconf() {
|
||||||
|
{ cat "$conf_cache"; test -f "$conf_extra" && cat "$conf_extra";
|
||||||
|
fd --hidden --type file --size -1m --max-depth 1 . ~;
|
||||||
|
find "$XDG_CONFIG_HOME" /etc -maxdepth 3 -type f -exec grep -lI '' {} +; } | dedup
|
||||||
|
}
|
||||||
|
conf_cache_dir="$XDG_CACHE_HOME/edconf"
|
||||||
|
conf_cache="$conf_cache_dir/files"
|
||||||
|
conf_tmp="${conf_cache}.tmp"
|
||||||
|
conf_extra="$XDG_CONFIG_HOME/edconf-extra"
|
||||||
|
mkdir -p "$conf_cache_dir"
|
||||||
|
touch "$conf_cache"
|
||||||
|
sel=$(listconf | fzf -1 -0 --tiebreak=end,length --preview '$(test -r "{}" || echo "sudo") bat --color=always --style=numbers --line-range :200 {}' --query="$1" --history "$conf_cache_dir/searches")
|
||||||
|
test "$sel" && ((echo "$sel" | cat - "$conf_cache" | head -20 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache") & edit "$sel")
|
Loading…
Reference in New Issue