2020-10-07 19:45:01 +00:00
|
|
|
|
# Shell aliases & functions for Zsh, works almost completely for Bash as well
|
|
|
|
|
|
2020-10-14 12:43:50 +00:00
|
|
|
|
if test "$ZSH_NAME" = "zsh"; then
|
|
|
|
|
alias -g ___='"$(eval "$(fc -ln -1)" | tail -n 1)"'
|
|
|
|
|
alias -g G="| grp"
|
|
|
|
|
alias -g X="| xargs"
|
2020-12-07 20:55:46 +00:00
|
|
|
|
alias -g X1="| xargs -n 1"
|
2021-04-22 17:37:32 +00:00
|
|
|
|
alias -g XC="| xclip -selection clipboard"
|
2021-05-07 10:31:14 +00:00
|
|
|
|
alias -g L="--color=always | ${PAGER:-less}"
|
2020-10-14 12:43:50 +00:00
|
|
|
|
fi
|
|
|
|
|
|
2021-07-02 16:32:09 +00:00
|
|
|
|
alias h='help'
|
2020-12-23 12:43:15 +00:00
|
|
|
|
alias info='info --vi-keys'
|
|
|
|
|
|
2021-07-06 22:48:35 +00:00
|
|
|
|
d() { cd $(zf "$@") }
|
2021-07-02 16:32:09 +00:00
|
|
|
|
alias c=z
|
|
|
|
|
alias v=edit
|
|
|
|
|
|
2020-12-23 12:43:15 +00:00
|
|
|
|
xdh="$XDG_DATA_HOME"
|
|
|
|
|
xch="$XDG_CONFIG_HOME"
|
2021-01-11 11:25:23 +00:00
|
|
|
|
if test -d "$DATA"; then
|
2021-05-05 06:55:44 +00:00
|
|
|
|
da=$(cd $DATA/_* && pwd)
|
|
|
|
|
d1=$(cd $DATA/1* && pwd)
|
|
|
|
|
d2=$(cd $DATA/2* && pwd)
|
|
|
|
|
d3=$(cd $DATA/3* && pwd)
|
|
|
|
|
d4=$(cd $DATA/4* && pwd)
|
2021-01-11 11:25:23 +00:00
|
|
|
|
fi 2>/dev/null
|
2020-12-23 12:43:15 +00:00
|
|
|
|
|
2020-10-07 19:45:01 +00:00
|
|
|
|
ulimit -c unlimited # Enable core dumps
|
2020-03-19 09:52:15 +00:00
|
|
|
|
|
2020-10-14 12:43:50 +00:00
|
|
|
|
which lsb_release >/dev/null && export DIST=$(lsb_release --id | cut -d' ' -f2) || true
|
|
|
|
|
|
2021-07-03 18:59:33 +00:00
|
|
|
|
compdef help=info
|
2021-02-15 19:57:17 +00:00
|
|
|
|
unalias rd 2>/dev/null
|
2020-11-16 11:29:31 +00:00
|
|
|
|
rd() {
|
2021-07-06 22:48:35 +00:00
|
|
|
|
for f in "$@"
|
2021-05-05 06:55:44 +00:00
|
|
|
|
do
|
2021-07-06 22:48:35 +00:00
|
|
|
|
if test -d "$f"; then
|
|
|
|
|
if test -d "$f/.git"
|
|
|
|
|
then echo "Force delete git project?" && read answer && test "$answer" = "y" && rm -rf "$f"
|
|
|
|
|
else find "$f" -maxdepth 1 -type d -empty -printf "Removing empty %p\n" -delete
|
|
|
|
|
fi
|
|
|
|
|
else rm -i "$f"
|
|
|
|
|
fi
|
2021-05-05 06:55:44 +00:00
|
|
|
|
shift
|
|
|
|
|
done
|
2020-11-16 11:29:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-26 19:32:26 +00:00
|
|
|
|
# like "which", but shows contents if it resolves to a file
|
|
|
|
|
wh() {
|
2021-05-05 06:55:44 +00:00
|
|
|
|
res=$(which "$@")
|
2021-07-06 22:48:35 +00:00
|
|
|
|
if expr "$res" : "${@:$#}: aliased to" >/dev/null
|
|
|
|
|
then echo "$res" && wh $(expr "$res" : "${@:$#}: aliased to ${@:$#} " >/dev/null && echo "-p") $(echo "$res" | cut -d' ' -f4)
|
|
|
|
|
# use command which for other shells
|
|
|
|
|
else test -r "$res" && b --style=header "$res" || echo "$res" | bat --style=plain --language=sh
|
|
|
|
|
fi
|
2020-11-26 19:32:26 +00:00
|
|
|
|
}
|
2021-07-02 16:32:09 +00:00
|
|
|
|
compdef wh=which
|
|
|
|
|
|
|
|
|
|
alias calc='rlwrap -a bc -l'
|
|
|
|
|
|
|
|
|
|
alias j='jrnl'
|
|
|
|
|
jn() { jrnl -to today "$@" | bat --style=plain --pager="less +G" }
|
|
|
|
|
compdef jn=jrnl
|
|
|
|
|
alias jnc='jn -contains'
|
2020-11-26 19:32:26 +00:00
|
|
|
|
|
2020-11-16 11:29:31 +00:00
|
|
|
|
alias logoff="loginctl terminate-user $USER"
|
2020-03-08 19:18:49 +00:00
|
|
|
|
|
2020-03-19 09:52:15 +00:00
|
|
|
|
# Some aliases
|
2021-02-15 19:57:17 +00:00
|
|
|
|
alias edgrub='sudoedit /etc/default/grub && sudo update-grub'
|
|
|
|
|
alias edenv='sudoedit /etc/environment'
|
|
|
|
|
alias edpart='sudoedit /etc/fstab && sudo findmnt --verify'
|
2020-06-08 09:41:03 +00:00
|
|
|
|
|
2020-10-23 20:17:58 +00:00
|
|
|
|
# Underline arg
|
|
|
|
|
highlight() { echo "[4m$1[0m" }
|
|
|
|
|
|
2020-09-04 10:09:08 +00:00
|
|
|
|
alias dedup='awk '"'"'!a[$0]++'"'"
|
2021-04-19 08:39:08 +00:00
|
|
|
|
listconf() {
|
|
|
|
|
{ cat "$conf_cache"; test -f "$conf_extra" && cat "$conf_extra";
|
|
|
|
|
fd --hidden --type file --size -1m --max-depth 1 . ~;
|
|
|
|
|
fd --hidden --type file --size -1m --max-depth 3 . --full-path "$XDG_CONFIG_HOME" /etc } | dedup
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 10:09:08 +00:00
|
|
|
|
edconf() {
|
|
|
|
|
conf_cache_dir="$XDG_CACHE_HOME/edconf"
|
|
|
|
|
conf_cache="$conf_cache_dir/files"
|
2020-06-26 21:25:53 +00:00
|
|
|
|
conf_tmp="${conf_cache}.tmp"
|
2020-09-04 10:09:08 +00:00
|
|
|
|
conf_extra="$XDG_CONFIG_HOME/edconf-extra"
|
|
|
|
|
mkdir -p "$conf_cache_dir"
|
2020-06-26 21:25:53 +00:00
|
|
|
|
touch "$conf_cache"
|
2021-04-19 08:39:08 +00:00
|
|
|
|
sel=$(listconf | fzf -1 -0 --tiebreak=end,length --preview 'bat --color=always --style=numbers --line-range :200 {}' --query="$1" --history "$conf_cache_dir/searches")
|
2020-06-26 21:25:53 +00:00
|
|
|
|
# | xargs file | grep text | cut -d':' -f1 # this filters out non-text files, but it's ridiculously slow
|
2020-11-22 18:55:59 +00:00
|
|
|
|
test "$sel" && ((echo "$sel" | cat - "$conf_cache" | head -30 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache") & edit "$sel")
|
2020-06-26 21:25:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 22:48:35 +00:00
|
|
|
|
alias hist='print -z $(history | tac | fzf --tiebreak=index | tr -s " " | cut -d" " -f5-)'
|
2021-07-06 00:00:56 +00:00
|
|
|
|
|
2020-06-08 09:41:03 +00:00
|
|
|
|
CONFIG_SHELL_FUNCTIONS="${BASH_SOURCE[0]:-${(%):-%x}}"
|
2021-07-06 22:48:35 +00:00
|
|
|
|
alias rs="reset && exec zsh"
|
2021-06-24 20:08:32 +00:00
|
|
|
|
edcomp() {
|
|
|
|
|
file=$(echo "$1" | sed 's/^\([^_]\)/_\1/')
|
|
|
|
|
$EDITOR "${fpath[-1]}/$file"
|
|
|
|
|
unfunction "$file" && compinit
|
|
|
|
|
}
|
|
|
|
|
compdef "_files -W ${fpath[-1]}/" edcomp
|
|
|
|
|
|
2020-09-04 10:09:08 +00:00
|
|
|
|
edshell() {
|
|
|
|
|
case $1 in
|
2020-11-13 12:33:44 +00:00
|
|
|
|
("") file="$CONFIG_SHELL_FUNCTIONS";;
|
|
|
|
|
(zsh) file="$CONFIG_ZSH/.zshrc";;
|
|
|
|
|
(prof*) file="$HOME/.zprofile";;
|
|
|
|
|
(*) file=$(find $CONFIG_SHELLS -name "$1*" | head -1);;
|
2020-09-04 10:09:08 +00:00
|
|
|
|
esac
|
2020-06-08 09:41:03 +00:00
|
|
|
|
checksum="$(md5sum $file)"
|
|
|
|
|
$EDITOR $file
|
2020-12-23 12:43:15 +00:00
|
|
|
|
test "$checksum" != "$(md5sum $file)" && source "$HOME/.zprofile" && exec $SHELL
|
2020-09-04 10:09:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
alias l="ls -l --almost-all --human-readable --group-directories-first --file-type"
|
2020-12-14 10:50:24 +00:00
|
|
|
|
cd() {
|
2021-05-05 06:55:44 +00:00
|
|
|
|
test ! -d "$1" && test $# -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
|
2020-12-14 10:50:24 +00:00
|
|
|
|
}
|
2020-03-08 19:18:49 +00:00
|
|
|
|
|
2020-10-07 19:45:01 +00:00
|
|
|
|
swap() {
|
|
|
|
|
mv -n $1 $1.tmp
|
|
|
|
|
mv -n $2 $1
|
|
|
|
|
mv -n $1.tmp $2
|
|
|
|
|
}
|
2020-09-04 10:09:08 +00:00
|
|
|
|
|
2021-05-05 06:56:23 +00:00
|
|
|
|
p() {
|
|
|
|
|
pass "$@" || pass edit "$@"
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 10:09:08 +00:00
|
|
|
|
# Task management & time tracking
|
2020-10-23 12:00:41 +00:00
|
|
|
|
t() {
|
2021-05-05 06:55:44 +00:00
|
|
|
|
if test "$#" -eq 0 && which tn >/dev/null
|
|
|
|
|
then tn
|
|
|
|
|
else
|
|
|
|
|
if test "$1" = "do"
|
|
|
|
|
then test "$2" -gt 0 2>/dev/null && task mod sched:today "${@:2}" || task add sched:today "${@:2}"
|
|
|
|
|
else task "$@"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2020-10-23 12:00:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-08 09:41:03 +00:00
|
|
|
|
alias tw='timew'
|
2020-09-04 10:09:08 +00:00
|
|
|
|
twsm() { timew summary $(date --date="Monday $1 week ago" -I) to tomorrow :ids ${@:2} }
|
2020-11-26 19:32:26 +00:00
|
|
|
|
alias twtest='( cp -r "$TIMEWARRIORDB" /tmp/tw-bak && TIMEWARRIORDB=/tmp/timewarriordb-test/$(date +%s) && mkdir -p "$TIMEWARRIORDB"/data && :> "$TIMEWARRIORDB"/timewarrior.cfg && $SHELL )'
|
2020-09-04 10:09:08 +00:00
|
|
|
|
|
2021-07-04 19:56:12 +00:00
|
|
|
|
alias expr='noglob expr'
|
2020-09-04 10:09:08 +00:00
|
|
|
|
alias lst='( last; last -f /var/log/wtmp.1 ) | grep -v "pts/" | tac | less +G'
|
2020-06-26 21:25:53 +00:00
|
|
|
|
alias lar='last | tac'
|
2020-09-04 10:09:08 +00:00
|
|
|
|
|
2021-01-23 19:00:31 +00:00
|
|
|
|
# Listen to loopback of mic
|
2021-03-01 11:00:43 +00:00
|
|
|
|
alias listen='pactl load-module module-loopback; echo "Press Enter to stop"; read; pactl unload-module module-loopback'
|
2021-01-23 19:00:31 +00:00
|
|
|
|
|
2020-12-10 16:34:56 +00:00
|
|
|
|
xo() {
|
2021-05-05 06:55:44 +00:00
|
|
|
|
while test $# -gt 0; do
|
|
|
|
|
xdg-open "$1"
|
|
|
|
|
shift
|
|
|
|
|
done
|
2020-12-10 16:34:56 +00:00
|
|
|
|
}
|
2020-09-04 10:09:08 +00:00
|
|
|
|
alias sqli='rlwrap sqlite3 -column -header -cmd .tables'
|
2021-07-06 22:48:35 +00:00
|
|
|
|
loc() { noglob locate --ignore-case --basename --existing "$@" | grep --color=always "$@" | less -F }
|
|
|
|
|
alias uloc='noglob sudo updatedb && loc'
|
2020-09-04 10:09:08 +00:00
|
|
|
|
alias syslog='less +F /var/log/syslog'
|
|
|
|
|
alias println='printf "\n"'
|
2021-02-10 17:04:04 +00:00
|
|
|
|
alias graphics='lspci -vnn | grep VGA --color=never && xrandr --listproviders'
|
2020-11-13 10:58:10 +00:00
|
|
|
|
alias usergroups="cat /etc/passwd | cut -d':' -f1 | xargs -n 1 id"
|
2020-12-07 20:55:46 +00:00
|
|
|
|
alias omd="(echo '#+OPTIONS: tags:nil'; xclip -o -selection clipboard) | pandoc -f org-auto_identifiers -t markdown --wrap preserve | xclip -filter"
|
2021-03-01 08:21:30 +00:00
|
|
|
|
alias mdo="pandoc -f gfm-ascii_identifiers-gfm_auto_identifiers -t org --wrap preserve"
|
2020-12-07 20:55:46 +00:00
|
|
|
|
alias mdox="xclip -o -selection clipboard | mdo | xclip -filter"
|
2021-01-03 14:01:52 +00:00
|
|
|
|
|
|
|
|
|
alias gdiff='git diff --word-diff=color --word-diff-regex=. --no-index'
|
2020-09-04 10:09:08 +00:00
|
|
|
|
|
2020-06-08 09:41:03 +00:00
|
|
|
|
alias sc='sudo systemctl'
|
2021-03-01 11:00:43 +00:00
|
|
|
|
alias sce='sudo systemctl enable --now'
|
2021-05-02 18:32:06 +00:00
|
|
|
|
scs() {
|
2021-05-18 21:40:58 +00:00
|
|
|
|
systemctl --user status "$1" "*$1*"
|
|
|
|
|
sudo systemctl status "$1" "*$1*"
|
2021-05-02 18:32:06 +00:00
|
|
|
|
}
|
2020-12-07 20:55:46 +00:00
|
|
|
|
alias scu='systemctl --user'
|
2021-03-01 11:00:43 +00:00
|
|
|
|
alias scue='systemctl --user enable --now'
|
2021-05-02 18:32:06 +00:00
|
|
|
|
|
|
|
|
|
scb() {
|
2021-05-05 06:55:44 +00:00
|
|
|
|
systemctl --user stop -T "$1"
|
2021-05-18 21:40:58 +00:00
|
|
|
|
sudo systemctl stop -T "$1"
|
2021-05-05 06:55:44 +00:00
|
|
|
|
read
|
|
|
|
|
systemctl --user start -T "$1"
|
2021-05-18 21:40:58 +00:00
|
|
|
|
sudo systemctl start -T "$1"
|
2021-05-02 18:32:06 +00:00
|
|
|
|
}
|
2020-09-04 10:09:08 +00:00
|
|
|
|
|
2021-01-18 19:57:59 +00:00
|
|
|
|
alias jcl='sudo SYSTEMD_LESS=FRKi journalctl --boot --no-hostname -e'
|
|
|
|
|
alias jc='jcl -u'
|
|
|
|
|
alias jcj='jcl -o json-pretty -u'
|
|
|
|
|
|
2021-07-06 22:48:35 +00:00
|
|
|
|
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 }
|
2020-10-14 12:16:36 +00:00
|
|
|
|
|
2020-09-04 10:09:08 +00:00
|
|
|
|
# Recover stray swap files from neovim
|
|
|
|
|
alias vrec="ls $XDG_DATA_HOME/nvim/swap | sed 's/\%/\//g' | sed 's|\(.*\)\..*|\1|' | head -1 | xargs -r nvim"
|
2020-11-14 01:26:30 +00:00
|
|
|
|
alias vrecd="ls $XDG_DATA_HOME/nvim/swap | head -1 | xargs -r -i mv {} /tmp"
|
|
|
|
|
|
|
|
|
|
unv() { strings $1 | sed 's/5$//' | dedup }
|
2020-03-08 19:18:49 +00:00
|
|
|
|
|
2021-06-08 18:44:42 +00:00
|
|
|
|
hex() { hexyl "$@" | "${PAGER:-less}" }
|
|
|
|
|
|
2020-09-04 10:09:08 +00:00
|
|
|
|
# Applications
|
2020-10-14 12:16:36 +00:00
|
|
|
|
alias dict="(builtin cd $XDG_DATA_HOME/dictcc && rlwrap perl dictcc-helper.pl)"
|
2020-09-04 10:09:08 +00:00
|
|
|
|
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'
|
2020-03-08 19:18:49 +00:00
|
|
|
|
|
2020-10-08 09:11:51 +00:00
|
|
|
|
test -d $HOME/.dropbox && dropbox_path="$(cat $HOME/.dropbox/info.json | grep -Po '"'"path"'"\s*:\s*"\K([^"]*)')"
|
2020-03-08 19:18:49 +00:00
|
|
|
|
|
|
|
|
|
# Add an "alert" alias for long running commands. Use like so: sleep 10; alert
|
|
|
|
|
#if [ command -v notify-send >/dev/null 2>&1 ]; then
|
|
|
|
|
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$//'\'')"'
|
|
|
|
|
#fi
|
|
|
|
|
|
2020-06-03 10:39:13 +00:00
|
|
|
|
sedcomment() { sed -i 's/$1/#\0/' "${@:2}" }
|
|
|
|
|
seduncomment() { sed -i 's/#\($1\)/\0/' "${@:2}" }
|
|
|
|
|
|
2020-03-08 19:18:49 +00:00
|
|
|
|
updateDeps() {
|
|
|
|
|
name="$1"
|
|
|
|
|
pattern="$2"
|
|
|
|
|
depth="4"
|
|
|
|
|
case $name in
|
2021-05-27 20:04:26 +00:00
|
|
|
|
(gradle-wrapper.properties) depth=6;;
|
2020-03-08 19:18:49 +00:00
|
|
|
|
esac
|
|
|
|
|
shift 2
|
|
|
|
|
oldversion="[0-9.]\+"
|
|
|
|
|
while test $# -gt 1; do
|
|
|
|
|
case "$1" in
|
2021-05-27 20:04:26 +00:00
|
|
|
|
(--pattern) oldversion="$2";;
|
|
|
|
|
(--version) version="$2";;
|
2020-03-08 19:18:49 +00:00
|
|
|
|
esac
|
|
|
|
|
shift 2
|
|
|
|
|
done
|
|
|
|
|
echo name $name depth $depth pattern $oldversion version $version
|
|
|
|
|
find -maxdepth $depth -type f -name $name | while read f
|
2021-05-05 06:55:44 +00:00
|
|
|
|
do echo $f
|
2020-03-08 19:18:49 +00:00
|
|
|
|
sed -i "s/\($pattern\)$oldversion/\1$version/gw /dev/stdout" $f
|
|
|
|
|
done
|
|
|
|
|
}
|
2020-09-04 10:09:08 +00:00
|
|
|
|
alias updateKotlin="updateDeps build.gradle.kts 'kotlin(\"jvm\") version ' --version"
|
2020-03-08 19:18:49 +00:00
|
|
|
|
alias updateGradle='updateDeps gradle-wrapper.properties "services.gradle.org\/distributions\/gradle-" --version'
|
|
|
|
|
alias updateUtils='updateDeps build.gradle.kts '\''\"com.github.Xerus2000.util\", \".*\", \"'\'' --pattern '\''[^\"]\+'\'' --version'
|
|
|
|
|
|
2020-06-03 10:39:13 +00:00
|
|
|
|
# Kill all shell background processes
|
2020-03-08 19:18:49 +00:00
|
|
|
|
alias killbg='kill ${${(v)jobstates##*:*:}%=*}'
|
|
|
|
|
|
2020-06-03 10:39:13 +00:00
|
|
|
|
# Kil all Java processes except IDEA
|
|
|
|
|
# Pass "-9" to force-kill and "-q" to not output what has been killed
|
2020-03-08 19:18:49 +00:00
|
|
|
|
killJava() {
|
|
|
|
|
pgrep -f 'java' | while read id
|
|
|
|
|
do if [[ $(ps --no-headers -o cmd $id) != *"idea"* ]]; then
|
|
|
|
|
[[ "$@" == "-q" ]] || echo "killing $(ps -p $id -o pid,cmd --width 350 --no-headers)"
|
|
|
|
|
if [[ "$@" == "-9" ]]
|
|
|
|
|
then kill -9 $id
|
|
|
|
|
else kill $id
|
|
|
|
|
fi
|
|
|
|
|
fi; done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearNpmCache() {
|
|
|
|
|
rm -rf $TMPDIR/react-*
|
|
|
|
|
rm -rf node_modules/
|
|
|
|
|
npm cache verify
|
|
|
|
|
npm install
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 23:20:02 +00:00
|
|
|
|
# NAVIGATION
|
2020-03-08 19:18:49 +00:00
|
|
|
|
|
2020-09-04 10:09:08 +00:00
|
|
|
|
alias rcd="cd $PWD"
|
|
|
|
|
cdd() { cd "$@" 2>/dev/null || cd "$(dirname "$1")" "${@:2}" }
|
|
|
|
|
|
2020-11-12 08:54:00 +00:00
|
|
|
|
# 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
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 10:09:08 +00:00
|
|
|
|
# Switch directory & ls
|
|
|
|
|
cl() {
|
|
|
|
|
builtin cd $1
|
|
|
|
|
ls --almost-all --group-directories-first --file-type
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 23:20:02 +00:00
|
|
|
|
# FILES
|
2020-03-08 19:18:49 +00:00
|
|
|
|
|
2021-04-19 08:39:08 +00:00
|
|
|
|
alias f="noglob $(which fd >/dev/null && echo fd || echo fdfind) --hidden --no-ignore-vcs --one-file-system"
|
2020-11-12 08:54:00 +00:00
|
|
|
|
#alias f='find -not -path "*.sync*" -and -not \( -name daten -prune \)'
|
|
|
|
|
#alias f1='find -mindepth 1 -maxdepth 1'
|
2020-03-08 19:18:49 +00:00
|
|
|
|
|
2021-04-22 17:37:32 +00:00
|
|
|
|
lowercase_transliterate="y/A-Z /a-z-/"
|
|
|
|
|
which perl-rename >/dev/null && alias lowercase="perl-rename '$lowercase_transliterate'" || alias lowercase="rename '$lowercase_transliterate'"
|
2020-03-08 19:18:49 +00:00
|
|
|
|
|
|
|
|
|
mkcd() {
|
2020-10-14 17:00:08 +00:00
|
|
|
|
mkdir -p "$1" && cd "$1"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# mv with automatic sudo if neccessary
|
|
|
|
|
smv() {
|
2020-11-13 10:58:10 +00:00
|
|
|
|
test -w "$1" && test -w "$(dirname $2)" && mv "$@" || sudo mv "$@"
|
2020-10-14 17:00:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Rename the file, keep it in its directory
|
|
|
|
|
mvf() {
|
|
|
|
|
smv "$1" "$(dirname $1)/$2"
|
2020-03-08 19:18:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-12 20:20:06 +00:00
|
|
|
|
# Moves from $1 to $2 and replaces the original with a relative symlink
|
2020-03-08 19:18:49 +00:00
|
|
|
|
mvln() {
|
|
|
|
|
file=$(test -f "$1" && echo 1 || echo 0)
|
|
|
|
|
if test -d $1; then
|
|
|
|
|
mkdir -p "$2"
|
|
|
|
|
mv -T $1 $2
|
|
|
|
|
else
|
|
|
|
|
mv -v $1 $2
|
|
|
|
|
fi
|
|
|
|
|
[ $file -gt 0 -a -d $2 ] && 2="$2/$(basename $1)"
|
2020-10-12 20:20:06 +00:00
|
|
|
|
ln -vsr "$2" "$1"
|
2020-03-08 19:18:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# OTHER
|
|
|
|
|
|
|
|
|
|
pathadd() {
|
|
|
|
|
local IFS=":"
|
|
|
|
|
local result="$@"
|
|
|
|
|
unset IFS
|
2021-03-26 18:03:16 +00:00
|
|
|
|
cat /etc/environment | head -1 | cut -d'"' -f2 | tr ":" "\n" | while read v
|
|
|
|
|
do [[ " $@ " =~ " $v " ]] || result+=":$v"
|
|
|
|
|
done
|
2020-03-08 19:18:49 +00:00
|
|
|
|
echo PATH=\"${result}\"\\n$(cat /etc/environment | tail -n +2) | sudo tee /etc/environment
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
writecompletion() {
|
|
|
|
|
echo "#compdef $1" > "_$1"
|
2020-09-04 10:09:08 +00:00
|
|
|
|
$EDITOR "_$1"
|
2020-03-08 19:18:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resetdocker() {
|
|
|
|
|
#aptremove docker-ce
|
|
|
|
|
kill $(ps -e | grep docker | cut -d' ' -f2)
|
|
|
|
|
sudo rm -rf /var/run/docker /var/lib/docker
|
|
|
|
|
sudo rm /var/run/docker.*
|
|
|
|
|
#aptinstall docker-ce
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# RANDOM
|
|
|
|
|
|
|
|
|
|
typeset -A _clean_map
|
|
|
|
|
if test "$BASH_VERSION"
|
2021-07-06 22:48:35 +00:00
|
|
|
|
then _clean_map=([h]=$XDG_CACHE_HOME [t]=/var/tmp)
|
|
|
|
|
else _clean_map=(h $XDG_CACHE_HOME t /var/tmp)
|
2020-03-08 19:18:49 +00:00
|
|
|
|
fi
|
2020-06-26 21:25:53 +00:00
|
|
|
|
_clean_folders=()
|
2020-03-08 19:18:49 +00:00
|
|
|
|
clean() {
|
|
|
|
|
for f in $_clean_folders
|
|
|
|
|
do test -d $f && rm -rv $f
|
|
|
|
|
done
|
2020-06-03 10:39:13 +00:00
|
|
|
|
|
2020-03-08 19:18:49 +00:00
|
|
|
|
highlight "g to clean gradle"
|
|
|
|
|
if [[ $1 =~ "g" ]]; then
|
2021-07-06 22:48:35 +00:00
|
|
|
|
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 {} +
|
2020-03-08 19:18:49 +00:00
|
|
|
|
fi
|
2020-06-03 10:39:13 +00:00
|
|
|
|
|
2020-09-04 10:09:08 +00:00
|
|
|
|
highlight "m to clean mac-files"
|
|
|
|
|
if [[ $1 =~ "m" ]]; then
|
|
|
|
|
find -iname '.spotlight*' -print -exec rm -r {} \;
|
2021-04-21 17:51:56 +00:00
|
|
|
|
find -name '*.DS_Store' -delete
|
2020-09-04 10:09:08 +00:00
|
|
|
|
fi
|
|
|
|
|
|
2021-07-06 22:48:35 +00:00
|
|
|
|
highlight "c to clean local 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 {} +
|
|
|
|
|
find -name "*build" -ok rm -r {} \; -prune
|
|
|
|
|
fi
|
|
|
|
|
|
2020-03-08 19:18:49 +00:00
|
|
|
|
if test "$BASH_VERSION"; then
|
|
|
|
|
for k in "${!_clean_map[@]}"; do
|
2020-09-04 10:09:08 +00:00
|
|
|
|
highlight "$k to delete $_clean_map[$k]"
|
2020-03-08 19:18:49 +00:00
|
|
|
|
echo "key : $k"
|
|
|
|
|
echo "value: ${_clean_map[$k]}"
|
|
|
|
|
done
|
|
|
|
|
else
|
|
|
|
|
for k in "${(@k)_clean_map}"; do
|
2020-09-04 10:09:08 +00:00
|
|
|
|
highlight "$k to delete $_clean_map[$k]"
|
2020-03-08 19:18:49 +00:00
|
|
|
|
[[ $1 =~ "$k" ]] && rm -rfv "$_clean_map[$k]"
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
2020-10-23 12:00:41 +00:00
|
|
|
|
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
|
2020-03-08 19:18:49 +00:00
|
|
|
|
|
2021-03-26 18:03:16 +00:00
|
|
|
|
|
2020-03-08 19:18:49 +00:00
|
|
|
|
highlight "e to delete empty folders"
|
|
|
|
|
[[ $1 =~ "e" ]] && find -empty -type d -delete -print
|
2021-03-30 16:09:04 +00:00
|
|
|
|
|
2021-04-21 17:51:56 +00:00
|
|
|
|
highlight "o to optimize extensively"
|
|
|
|
|
if [[ $1 =~ "o" ]]; then
|
2021-05-18 21:40:58 +00:00
|
|
|
|
which yay &>/dev/null && yay -Sc --noconfirm
|
2021-04-21 17:51:56 +00:00
|
|
|
|
nix-collect-garbage -d
|
|
|
|
|
nix-store --optimize
|
|
|
|
|
fi
|
2020-03-08 19:18:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-03 10:39:13 +00:00
|
|
|
|
function zipdiff() {
|
2020-03-08 19:18:49 +00:00
|
|
|
|
diff -W200 -y <(unzip -vql $1 | sort -k8) <(unzip -vql $2 | sort -k8) #--suppress-common-lines
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# SWAP
|
2020-09-04 10:09:08 +00:00
|
|
|
|
alias memstat='free -h | awk '"'"'NR==2 {printf "Free memory:\t %s/%s\t(%d%)\n",$7,$2,$7*100/$2} NR==3 {if($2 != "0B") printf "Used swap:\t%s/%s\t(%d%)\n",$3,$2,$2*100/$3}'"'"
|
2020-03-08 19:18:49 +00:00
|
|
|
|
|
|
|
|
|
stopswap() {
|
2020-09-04 10:09:08 +00:00
|
|
|
|
memstat
|
|
|
|
|
swap_used=$(cat /proc/meminfo | grep SwapFree | awk '{print $2}')
|
|
|
|
|
mem_available=$(cat /proc/meminfo | grep MemAvailable | awk '{print $2}')
|
|
|
|
|
if test $swap_used = 0
|
2020-03-08 19:18:49 +00:00
|
|
|
|
then echo "No swap is in use."
|
2020-09-04 10:09:08 +00:00
|
|
|
|
elif test $swap_used + 100000 < $mem_available
|
2020-03-08 19:18:49 +00:00
|
|
|
|
then echo "Freeing swap..."
|
|
|
|
|
sudo swapoff -a
|
|
|
|
|
sudo swapon -a
|
2020-09-04 10:09:08 +00:00
|
|
|
|
memstat
|
2020-03-08 19:18:49 +00:00
|
|
|
|
else
|
|
|
|
|
echo "Not enough free memory!"
|
|
|
|
|
fi
|
|
|
|
|
}
|