diff --git a/bash_aliases b/bash_aliases new file mode 100644 index 0000000..418fa6b --- /dev/null +++ b/bash_aliases @@ -0,0 +1,106 @@ +# ====== +# shorts +# ====== +alias l='ls -l' +alias k='ls -la' +function ö { l --color $1 | less; } +function j { if ! [ -z $2 ]; then k --color $1 | grep -i $2 --color=never; else k --color | grep -i $1 --color=never; fi;} + +# ============================ +# expanded commands / "macros" +# ============================ +function grepr { grep -n -i -r "${@:1}" . --color=always | grep -v -e "Binär" -e "Binary file" -e "rr-cache"; } +function grepnr { grep -n -r "${@:1}" . --color=always | grep -v -e "Binär" -e "Binary file" -e "rr-cache"; } +function runs { ps -ef | grep $1 | grep -v grep; } +function timestamptodate { date -d @$1; } +alias svim="sudo -E vim" +alias upgrade='sudo apt-fast update && sudo apt-fast upgrade' +alias aliases='vim ~/.bash_aliases; unalias -a && source ~/.bashrc' +alias realias='unalias -a && source ~/.bashrc' +alias rebash='unalias -a && source ~/.profile' + +# ============= +# redefinitions +# ============= +alias curl='curl -L' +alias less='less -R' +alias gpg='gpg --pinentry-mode=loopback --no-symkey-cache' + +# ======= +# systemd +# ======= +alias sctl="sudo systemctl" +alias uctl="systemctl --user" +alias slogf="journalctl -f --output cat -u" +alias ulogf="journalctl -f --output cat --user-unit" +alias slog="journalctl --output cat -u" +alias ulog="journalctl --output cat --user-unit" +function ulogsince { string="${@:2}"; ulog $1 --since "$string"; } +function slogsince { string="${@:2}"; slog $1 --since "$string"; } +function ustartenable { uctl enable $1 && urefo $1; } +function ustopdisable { uctl disable $1 && uctl stop $1; } +function srefo { sudo systemctl restart "$1" & journalctl -f -u "$1" --output cat; } +function urefo { systemctl --user restart "$1" & ulogf "$1"; } +alias unbuffer='unbuffer ' +function uctlstatus { for unit in $(systemctl --user list-unit-files | grep "enabled" | grep ".service" | grep -v -e "disabled" -e ".timer" -e ".target" -e ".socket" | awk '{print $1}'); do echo "Unit: $unit"; unbuffer systemctl --user status $unit --output cat --no-pager | grep -e ".service -" -e "Active" --color=never; echo ""; done; } + +# ===== +# nginx +# ===== +alias renginx='sudo nginx -t && sudo nginx -s reload' +alias restartnginx='sudo nginx -t && sudo systemctl restart nginx' +function nable { sudo ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/; } + +# ======================= +# (log) file manipulation +# ======================= +# pipe log into this function or supply file as 2nd arg to start displaying logs only after first match +function catafter { if ! [ -z $2 ]; then sed -e "1,/$1/d" "$2"; else sed -e "1,/$1/d"; fi; } +# $1 = file, $2 = first line to show, $3 = last line to show +function linesfromto { tail -n +$2 $1 | head -n $(($3-$2+1)); } +# tail multiple log files in one stream +# stdbuf: https://superuser.com/a/1123674 +# awk magic: https://unix.stackexchange.com/a/195930 +function mtail { tail -f ${@:1} | stdbuf -o0 awk '/^==> / {a=substr($0, 5, length-8); next} {print a":"$0}' | grep --line-buffered -v ":$"; } + +# ================== +# extended functions +# ================== +function json_validator { python3 -mjson.tool "$1" > /dev/null && echo "Valid JSON!" || echo "JSON validation FAILED!"; } +function checkpy { pyflakes "$1"; pycodestyle --ignore=E402 --ignore=W503 --max-line-length=120 "$1"; deactivate; echo "Done"!; } +function random-string { if ! [ -z "$1" ]; then len=$1; else len=32; fi; cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1 | cut -c -$len; } + +# === +# git +# === +alias lastcommit='git log --name-status HEAD^..HEAD' +alias lastcommitdiff='git diff HEAD^ HEAD' +alias redocommit='git commit -c ORIG_HEAD' +alias undocommit='git reset HEAD~' +function deletebranch { git push --delete origin $1; git branch -d $1 || git branch -D $1; } +function addtheirs { git checkout --theirs "$@" && git add "$@"; } +function addours { git checkout --ours "$@" && git add "$@"; } +# https://coderwall.com/p/_8dxjw/merging-a-pull-request-locally +function mergePR { git fetch $1 refs/pull/$2/head && git merge FETCH_HEAD; } +function resolvestash { git restore --staged . && git stash drop; } + +# ===== +# MySQL +# ===== +function mysqldump_extract_table () { + dump=$1 + table=$2 + sed -n -e "/CREATE TABLE.\`*$table\`/,/Table structure for table/p" $dump > $dump-$table.sql +} + +# ====== +# kotlin +# ====== +function ktrun { kotlinc $1 -include-runtime -d $1.jar; java -jar $1.jar; } + +# === +# APK +# === +function apkversion { aapt dump badging $1 | grep versionName | awk '{print $4}' | cut -d = -f 2 | tr -d \'; } +function apkarchitecture { aapt dump badging $1 | grep native-code | cut -d : -f2 | sed "s/'//g" | sed "s/ //g"; } +