bash_aliases/.bash_aliases
2022-08-27 12:33:40 +02:00

251 lines
8.7 KiB
Bash

export EDITOR=nvim
export HOSTNAME=`hostname 2>/dev/null || hostnamectl hostname`
export RIPGREP_CONFIG_PATH=~/.ripgreprc
if [ $USER = 'knyffen' ] || ([ $HOSTNAME = 'jry-thinkpad-t470' ] && [ $USER = 'jry' ]); then
alias rm="trash"
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"
alias wol_desktop="ssh knyf wol BC:5F:F4:74:74:57"
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 ~/openvpn/jobindex.conf"
alias enable_touch="xinput enable 'Wacom HID 51E3 Finger touch'"
alias disable_touch="xinput disable 'Wacom HID 51E3 Finger touch'"
alias pacman="nice -n 19 pacman"
alias yay="nice -n 19 yay"
alias restartplasma='kquitapp5 plasmashell && kstart5 plasmashell'
alias ack="ack -T junkFiles"
function ack_open { nvim $( ack -m 1 -T junkFiles "$@" | grep -Po "^(?:lib|t|tmpl|python)/[^:]+:\d+" | tr '\n' ' ' ); }
# git
alias gst="git status"
if [ `alias | grep '\sgbr=' | wc -l` != 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) ^master --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) ^master --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; }
# 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
}
alias TODO="ggn 'TODO: jry:?'"
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;
}
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 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/"
function profiling {
local JIX_USERID=233476; # userid of JRY
local USER=jobdk;
local ROOT=$1;
shift;
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("'$USER'"); # backup solution for setting USER=jobdk env variable
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_companyuser($c);
$t->jix_get_ok([ "'$ROOT'", format=>"xml", form => { '$FORM' } ]);
for (0..9) {
$t->login_companyuser($c);
DB::enable_profile;
$t->jix_get_ok([ "'$ROOT'", format=>"xml", form => { '$FORM' } ]);
DB::disable_profile;
};
done_testing();';
echo "Command:";
echo "perl -d:NYTProf -E '$COMMAND'";
USER=jobdk NYTPROF=start=no perl -d:NYTProf -E "$COMMAND";
nytprofhtml;
}
# 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