export EDITOR=nvim export HOSTNAME=$(hostname 2>/dev/null || hostnamectl hostname) export RIPGREP_CONFIG_PATH=~/.ripgreprc export PATH="$PATH:/opt/cuda/nsight_systems/bin:/opt/cuda/nsight_compute" export PATH="$(systemctl --user show-environment | grep "^PATH" | sed -e 's/PATH=//g'):$PATH" export HISTCONTROL=erasedups if [ $USER = 'knyffen' ] || ([ $HOSTNAME = 'jry-thinkpad-t470' ] && [ $USER = 'jry' ]); then alias rm="trash" alias reboot="qdbus org.kde.Shutdown /Shutdown logoutAndReboot" fi #if [ $USER = 'knyffen' ]; then # alias rm="trash" # alias ssh-add="ssh-add /home/knyffen/.ssh/knyf-inator /home/knyffen/.ssh/Knyf-inatorV2 /home/knyffen/.ssh/git_knyffen_dk" #fi # #if [ $USER = 'jry' ]; then # alias ssh-add="ssh-add /home/jry/.ssh/knyf-inator /home/jry/.ssh/Knyf-inatorV2 /home/jry/.ssh/git_knyffen_dk /home/jry/.ssh/id_rsa" #fi alias sudo="sudo " alias vim="nvim" alias vi="nvim" alias ghc="ghc -dynamic" alias find_root="sudo find / 2>&1" alias py="python" alias zathura-t="tabbed -c zathura -e" alias parsecd="LIBVA_DRIVER_NAME=iHD parsecd" alias stack="/usr/bin/stack" alias java_hidpi="java -Dsun.java2d.uiScale=2" function wol_desktop { wol A0:36:BC:BA:A1:58; while ! ping -c 1 -n -w 1 192.168.0.53 &> /dev/null do echo -n .; done echo ''; sleep 5s; ssh root@192.168.0.53; sleep 5s; ssh -t knyffen@192.168.0.53 'sudo systemctl restart sddm'; } alias wol_synology="ssh knyf wol 00:11:32:09:9F:12" alias dd_progress='sudo kill -USR1 $(pgrep ^dd)' alias co2="ssh knyf mhz14a -r -d /dev/ttyS0" alias h2o="ssh knyf 'cd configfiles/BME280; ./get_temperature_humidity_and_idead_humidity.sh'" alias probox="vim /home/knyffen/Nextcloud/Notes/Probox.md" alias rebuild-detector="checkrebuild -v" alias jix-vpn="sudo openvpn --config ~/Nextcloud/configfiles/openvpn/jobindex.conf" alias enable_touch="xinput enable 'Wacom HID 51E3 Finger touch'" alias disable_touch="xinput disable 'Wacom HID 51E3 Finger touch'" alias ack="ack -T junkFiles" function ack_open { nvim "$( ack -m 1 -T junkFiles "$@" | grep -Po "^(?:lib|t|tmpl|python)/[^:]+:\d+" | tr '\n' ' ' )"; } alias pacman="nice -n 19 pacman --config ~/Nextcloud/configfiles/pacman/pacman.conf" alias downgrade="nice -n 19 downgrade --pacman-conf ~/Nextcloud/configfiles/pacman/pacman.conf" alias yay="nice -n 19 yay --config ~/Nextcloud/configfiles/pacman/pacman.conf" alias makepkg="nice -n 19 makepkg" alias restartplasma='systemctl --user restart plasma-plasmashell' alias surf="GDK_BACKEND=x11 surf" alias nvim-restore="ls ~/.local/share/nvim/swap/ | xargs basename -s .swp | tr % / | xargs nvim" alias rmlint="rmlint -o pretty:stdout" alias clear="seq 2 $(tput lines) | xargs -n 1 echo; clear -x" alias decolor="sed -e 's/\x1b\[[0-9;]*m//g'" alias restart_vban="systemctl --user restart vban; ssh knyffen@192.168.0.20 sudo systemctl restart vban" alias count_files_in_folders="du -a | cut -d/ -f2 | sort | uniq -c | sort -n" function zip_it { zip -r "$1" "$1"; } # function unzip { # if (( "$#" == 1 )) # then # FOLDER=$(basename "$1" .zip) # command unzip "$1" -d "$FOLDER" # return # fi # command git "$@" # unzip -r "$1" "$1"; # } # git alias gst="git status" if [ "$(alias | grep '\sgbr=' -c)" != 0 ]; then unalias gbr fi # alias gbr="git branch --sort=-committerdate" # function gbr2 { git branch --sort=-committerdate | perl -pE 'my $branch = $_ =~ s/^[*+]?\s(\S+)\s*$/$1/r; my $merged = qx{git log \$(git rev-parse $branch) ^main --no-merges}; if ($merged) { $_ =~ s/^/[ ] / } else { $_ =~ s/^/[x] / };'; } function gbr { git branch --sort=-committerdate --format '%(if)%(HEAD)%(then)*%(else)%(if)%(worktreepath)%(then)+%(else) %(end)%(end) %(align:width=40,position=left)%(refname:short)%(end) %(align:width=10,position=right)%(color:green)(%(committerdate:relative))%(end)' | perl -pE '$_ =~ /^[*+]?\s+(?\S+)\s*/; my $branch = $+{branch}; my $merged = qx{git log \$(git rev-parse $branch) ^main --no-merges}; if ($merged) { $_ =~ s/^/[ ] / } else { $_ =~ s/^/[x] / };'; } function ggn { git grep -Pn --color=always "$@" :/; } function ggt { git grep -Pn --color=always "$@" t/lib ; } function ggp { ggn --color=always "$@" "$(git rev-list --all)"; } function ggl { ggn --color=always "$@" | less -R; } function gdl { git diff --color=always "$@" | less -R; } function ggtl { ggt --color=always "$@" | less -R; } function ggpl { ggp --color=always "$@" | less -R; } function rgl { rg --color=always "$@" | less -R; } function vimgst { nvim $(git status -s | cut -d ' ' -f 3 | tr '\n' ' '); } # git grep colors git config --global color.grep.filename "Green" git config --global color.grep.linenumber "Yellow" git config --global color.grep.match "bold #ff4d00" git() { local subcommand1 local subcommand2 if (( "$#" == 0 )); then command git; return; fi subcommand1=$1; shift case $subcommand1 in stash) if (( "$#" == 0 )); then command git stash; return; fi subcommand2=$1; shift case $subcommand2 in list) command git stash list --pretty=format:"%C(bold magenta)%gd%C(reset): %<|(110)%s %C(green)(%cr)" "$@" ;; *) command git "$subcommand1" "$subcommand2" "$@" ;; esac ;; *) command git "$subcommand1" "$@" ;; esac } if [ "$HOSTNAME" = 'gnu' ] && [ "$USER" = 'jry' ]; then alias TODO="ggn 'TODO: jry:?'" fi if [ "$USER" = 'knyffen' ] || [ "$HOSTNAME" = 'jry-thinkpad' ]; then alias TODO="vim ~/Nextcloud/Notes/TODO.md" fi title() { # set input argument as window title echo -ne "\033]30;$1\007" } expressvpn() { local subcommand if [ $# -eq 0 ]; then command expressvpn; return; fi subcommand=$1; shift case $subcommand in connect) if ! (command expressvpn "status" | grep -i "$@"); then command expressvpn "disconnect"; fi command "sudo /usr/bin/cp -f /etc/resolv.conf /etc/resolv.conf.backup" command expressvpn "$subcommand" "$@" ;; disconnect) command expressvpn "$subcommand" "$@" command "sudo /usr/bin/cp -f /etc/resolv.conf.backup /etc/resolv.conf" ;; *) command expressvpn "$subcommand" "$@" ;; esac } alias vpn=nordvpn nordvpn() { local subcommand if [ $# -eq 0 ]; then command nordvpn; return; fi subcommand=$1; shift case $subcommand in c) command nordvpn "$subcommand" "$@" ;; connect) command nordvpn "$subcommand" "$@" ;; d) command nordvpn "$subcommand" "$@" # command echo 'nameserver 192.168.1.1' | sudo tee /etc/resolv.conf command sudo cp -f /etc/resolv.conf.bak /etc/resolv.conf ;; disconnect) command nordvpn "$subcommand" "$@" # command echo 'nameserver 192.168.1.1' | sudo tee /etc/resolv.conf command sudo cp -f /etc/resolv.conf.bak /etc/resolv.conf ;; *) command nordvpn "$subcommand" "$@" ;; esac } spin() { local subcommand local fname if [ $# -eq 0 ]; then command spin; return; fi subcommand=$1; shift case $subcommand in run) shift command spin "-run $@" ;; run_bfs) shift command spin "-run -bfs $@" ;; run_fair) shift command spin "-run -f $@" ;; run_bfs_fair) shift command spin "-run -bfs -f $@" ;; trace) shift fname=$1; shift command "./pam -i $fname" command "./pam -r $@ $fname" ;; trace_depth) shift local depth fname=$1; shift depth=$1; shift command "./pam -m$depth -i $fname" command "./pam -m$depth -r $@ $fname" ;; *) command spin "$subcommand $@" esac; } pdfpagepicker() { if [ -z "$(pacman -Qs poppler | grep 'local/poppler ')" ]; then echo "This script requires poppler to be installed." echo "sudo pacman -S poppler" return fi if [ $# != 3 ]; then echo "Usage: input.pdf 1,3-5,7 output.pdf" return fi IN=$1 PAGES=$2 OUT=$3 FOLDERNAME='.tmpmyverysecrettmpfolderaasdasdasdaastf' [ ! -d "$FOLDERNAME" ] || { echo "Failed! Temporary folder already exists."; exit; } mkdir "$FOLDERNAME" cd "$FOLDERNAME" || { echo "Failed! Couldn't create temporary folder."; exit; } pdfseparate "../$IN" page_%d.pdf set -- $( echo "$PAGES" | perl -E 'say "page_$_.pdf" foreach map {eval($_ =~ s/-/../r)} split(/,/, <>)' ); pdfunite "$@" "../$OUT" cd .. rm -r "$FOLDERNAME" } if [ "$USER" = 'knyffen' ]; then # Reduce priority of make commands, to preserve system responsiveness when e.g. compiling gcc alias pamac="nice -n 19 pamac" fi if [ "$HOSTNAME" = 'gnu' ] && [ "$USER" = 'jry' ]; then alias fzy="~/.fzy/fzy" alias perlperl="/usr/bin/perl" alias perlprove="/usr/bin/prove" function prove { jix-shell TEST_METHOD="$TEST_METHOD" BAIL_ON_FAIL="$BAIL_ON_FAIL" prove "$@"; } function prove-on-backend { jix-shell TEST_METHOD="$TEST_METHOD" BAIL_ON_FAIL="$BAIL_ON_FAIL" USER="$USER" JIX_USERID="$JIX_USERID" prove-on-backend "$@"; } function perl { jix-shell TEST_METHOD="$TEST_METHOD" BAIL_ON_FAIL="$BAIL_ON_FAIL" USER="$USER" JIX_USERID="$JIX_USERID" perl -MJIX "$@"; } alias jix-schedule="jix-shell jix-schedule" alias open_url="jix-shell open_url" alias colorlog="jix-shell colorlog.pl" alias jix-gettext="jix-shell jix-gettext" alias arc="jix-shell arc" alias solr="ssh -L 1214:localhost:8983 solr@gnu.dev.job.dk firefox http://localhost:1214/solr/" alias push-to-production="jix-shell push_to_production.sh" function profiling { local JIX_USERID=233476; # userid of JRY local ENV_USER=jobdk; # Don't call it USER, since that changes the user the process runs at, and then it cannot save the output local ROOT=$1; shift; if [[ $# -ge 1 ]]; then local FORMAT=$1; shift; else local FORMAT=; fi local FORM=$@; local COMMAND='use Test::More; use Test::JIX::Mojo; use JIX::Env; DB::disable_profile; # backup solution for setting NYTPROF=start=no env variable JIX::Env->USER("'$ENV_USER'"); # backup solution for setting USER=jobdk env variable use JIX::CHI; JIX::CHI->reset; # Clear all caches my $t = Test::JIX::Mojo->new("JIX::Mojo"); my $c = JIX::CompanyUser->retrieve( { id => '"$JIX_USERID"' } ); $t->ua->inactivity_timeout(600); $t->auto_html5_ok(0); $t->login_admin_companyuser($c); $t->jix_get_ok([ "'$ROOT'", format => "'$FORMAT'", form => { '"$FORM"' } ]); for (0..9) { $t->login_admin_companyuser($c); DB::enable_profile; $t->jix_get_ok([ "'$ROOT'", format => "'$FORMAT'", form => { '"$FORM"' } ]); DB::disable_profile; }; done_testing();'; echo "Command:"; echo "perl -d:NYTProf -E '$COMMAND'"; jix-shell USER="$ENV_USER" NYTPROF=start=no perl -d:NYTProf -E "$COMMAND"; rm -rf nytprof; jix-shell nytprofhtml; rm -rf nytprof.out; } # Automatically keep a pointer to my latest SSH agent MY_SSH_SOCK="/tmp/ssh-agent-$USER" if test "$SSH_AUTH_SOCK" && [ "$SSH_AUTH_SOCK" != "$MY_SSH_SOCK" ]; then ln -sf "$SSH_AUTH_SOCK" "$MY_SSH_SOCK" export SSH_AUTH_SOCK="$MY_SSH_SOCK" fi fi