bash_aliases/.bash_aliases

333 lines
12 KiB
Bash
Raw Permalink Normal View History

2021-01-16 23:49:53 +01:00
export EDITOR=nvim
2023-09-01 13:01:27 +02:00
export HOSTNAME=$(hostname 2>/dev/null || hostnamectl hostname)
export RIPGREP_CONFIG_PATH=~/.ripgreprc
2023-09-01 13:01:27 +02:00
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"
2024-08-17 16:29:44 +02:00
export HISTCONTROL=erasedups
2021-01-16 23:49:53 +01:00
if [ $USER = 'knyffen' ] || ([ $HOSTNAME = 'jry-thinkpad-t470' ] && [ $USER = 'jry' ]); then
2021-01-16 23:49:53 +01:00
alias rm="trash"
alias reboot="qdbus org.kde.Shutdown /Shutdown logoutAndReboot"
2021-01-16 23:49:53 +01:00
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
2021-01-16 23:22:50 +01:00
alias sudo="sudo "
alias vim="nvim"
2021-01-16 23:49:53 +01:00
alias vi="nvim"
2021-01-16 23:22:50 +01:00
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"
2023-09-01 13:01:27 +02:00
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"
2021-01-16 23:22:50 +01:00
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"
2022-09-01 20:22:05 +02:00
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"
2023-09-01 13:01:27 +02:00
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"
2024-08-17 16:29:44 +02:00
alias downgrade="nice -n 19 downgrade --pacman-conf ~/Nextcloud/configfiles/pacman/pacman.conf"
2023-09-01 13:01:27 +02:00
alias yay="nice -n 19 yay --config ~/Nextcloud/configfiles/pacman/pacman.conf"
alias makepkg="nice -n 19 makepkg"
2022-09-09 12:18:54 +02:00
alias restartplasma='systemctl --user restart plasma-plasmashell'
alias surf="GDK_BACKEND=x11 surf"
2022-10-12 16:12:03 +02:00
alias nvim-restore="ls ~/.local/share/nvim/swap/ | xargs basename -s .swp | tr % / | xargs nvim"
2022-10-12 16:21:08 +02:00
alias rmlint="rmlint -o pretty:stdout"
2023-09-01 13:01:27 +02:00
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"; }
2024-08-17 16:29:44 +02:00
# function unzip {
# if (( "$#" == 1 ))
# then
# FOLDER=$(basename "$1" .zip)
# command unzip "$1" -d "$FOLDER"
# return
# fi
# command git "$@"
# unzip -r "$1" "$1";
# }
2021-01-16 23:22:50 +01:00
2021-01-16 23:49:53 +01:00
# git
alias gst="git status"
2023-09-01 13:01:27 +02:00
if [ "$(alias | grep '\sgbr=' -c)" != 0 ]; then
unalias gbr
fi
2022-04-27 09:43:35 +02:00
# alias gbr="git branch --sort=-committerdate"
2024-08-20 09:13:46 +02:00
# 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+(?<branch>\S+)\s*/; my $branch = $+{branch}; my $merged = qx{git log \$(git rev-parse $branch) ^main --no-merges}; if ($merged) { $_ =~ s/^/[ ] / } else { $_ =~ s/^/[x] / };'; }
2021-01-16 23:49:53 +01:00
function ggn { git grep -Pn --color=always "$@" :/; }
function ggt { git grep -Pn --color=always "$@" t/lib ; }
2023-09-01 13:01:27 +02:00
function ggp { ggn --color=always "$@" "$(git rev-list --all)"; }
2021-01-16 23:49:53 +01:00
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; }
2022-10-12 16:19:51 +02:00
function rgl { rg --color=always "$@" | less -R; }
2023-10-06 09:05:40 +02:00
function vimgst { nvim $(git status -s | cut -d ' ' -f 3 | tr '\n' ' '); }
2021-01-16 23:49:53 +01:00
# 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
}
2023-09-01 13:01:27 +02:00
if [ "$HOSTNAME" = 'gnu' ] && [ "$USER" = 'jry' ]; then
2022-10-12 16:21:08 +02:00
alias TODO="ggn 'TODO: jry:?'"
fi
2023-09-01 13:01:27 +02:00
if [ "$USER" = 'knyffen' ] || [ "$HOSTNAME" = 'jry-thinkpad' ]; then
2022-10-12 16:21:08 +02:00
alias TODO="vim ~/Nextcloud/Notes/TODO.md"
fi
2021-01-16 23:49:53 +01:00
2021-01-16 23:22:50 +01:00
title() {
2021-01-16 23:49:53 +01:00
# set input argument as window title
2021-01-16 23:22:50 +01:00
echo -ne "\033]30;$1\007"
}
expressvpn() {
2021-01-16 23:49:53 +01:00
local subcommand
if [ $# -eq 0 ]; then command expressvpn; return; fi
2021-01-16 23:49:53 +01:00
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
2021-01-16 23:22:50 +01:00
}
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
}
2021-01-16 23:22:50 +01:00
spin() {
local subcommand
local fname
if [ $# -eq 0 ]; then command spin; return; fi
2021-01-16 23:22:50 +01:00
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;
}
2021-01-16 23:49:53 +01:00
2023-09-01 13:01:27 +02:00
pdfpagepicker() {
if [ -z "$(pacman -Qs poppler | grep 'local/poppler ')" ]; then
echo "This script requires poppler to be installed."
echo "sudo pacman -S poppler"
2024-08-17 16:29:44 +02:00
return
2023-09-01 13:01:27 +02:00
fi
if [ $# != 3 ]; then
echo "Usage: input.pdf 1,3-5,7 output.pdf"
2024-08-17 16:29:44 +02:00
return
2023-09-01 13:01:27 +02:00
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
2023-09-01 13:01:27 +02:00
if [ "$HOSTNAME" = 'gnu' ] && [ "$USER" = 'jry' ]; then
2021-01-16 23:49:53 +01:00
alias fzy="~/.fzy/fzy"
2022-04-27 09:43:35 +02:00
alias perlperl="/usr/bin/perl"
alias perlprove="/usr/bin/prove"
2023-09-01 13:01:27 +02:00
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 "$@"; }
2024-08-20 09:13:46 +02:00
alias jix-schedule="jix-shell jix-schedule"
2022-04-27 09:43:35 +02:00
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"
2024-08-20 09:13:46 +02:00
alias solr="ssh -L 1214:localhost:8983 solr@gnu.dev.job.dk firefox http://localhost:1214/solr/"
2022-10-12 16:12:03 +02:00
alias push-to-production="jix-shell push_to_production.sh"
2021-01-16 23:49:53 +01:00
function profiling {
local JIX_USERID=233476; # userid of JRY
2024-08-20 09:13:46 +02:00
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
2021-01-16 23:49:53 +01:00
local ROOT=$1;
shift;
2024-08-20 09:13:46 +02:00
if [[ $# -ge 1 ]]; then
local FORMAT=$1;
shift;
else
local FORMAT=;
fi
2021-01-16 23:49:53 +01:00
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
2024-08-20 09:13:46 +02:00
JIX::Env->USER("'$ENV_USER'"); # backup solution for setting USER=jobdk env variable
use JIX::CHI;
JIX::CHI->reset; # Clear all caches
2021-01-16 23:49:53 +01:00
my $t = Test::JIX::Mojo->new("JIX::Mojo");
2023-09-01 13:01:27 +02:00
my $c = JIX::CompanyUser->retrieve( { id => '"$JIX_USERID"' } );
2021-01-16 23:49:53 +01:00
$t->ua->inactivity_timeout(600);
$t->auto_html5_ok(0);
2024-08-20 09:13:46 +02:00
$t->login_admin_companyuser($c);
$t->jix_get_ok([ "'$ROOT'", format => "'$FORMAT'", form => { '"$FORM"' } ]);
2021-01-16 23:49:53 +01:00
for (0..9) {
2024-08-20 09:13:46 +02:00
$t->login_admin_companyuser($c);
2021-01-16 23:49:53 +01:00
DB::enable_profile;
2024-08-20 09:13:46 +02:00
$t->jix_get_ok([ "'$ROOT'", format => "'$FORMAT'", form => { '"$FORM"' } ]);
2021-01-16 23:49:53 +01:00
DB::disable_profile;
};
done_testing();';
echo "Command:";
echo "perl -d:NYTProf -E '$COMMAND'";
2024-08-20 09:13:46 +02:00
jix-shell USER="$ENV_USER" NYTPROF=start=no perl -d:NYTProf -E "$COMMAND";
rm -rf nytprof;
jix-shell nytprofhtml;
rm -rf nytprof.out;
2021-01-16 23:49:53 +01:00
}
# Automatically keep a pointer to my latest SSH agent
MY_SSH_SOCK="/tmp/ssh-agent-$USER"
2023-09-01 13:01:27 +02:00
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"
2021-01-16 23:49:53 +01:00
fi
fi