# Multi machine export PATH=$HOME/arjoonncom/website/content/static/bin:$PATH export PATH="$HOME/gems/bin:$PATH" export PATH="$HOME/vim/build/bin:$PATH" export PATH="$HOME/Software/zed.app/bin:$PATH" gpt(){ curl -s -X POST --data-binary "Return one line answers when possible. $1" 'http://localhost:9002' echo } aider(){ (docker pull paulgauthier/aider-full 2>&1 > /dev/null) & docker run -it --user $(id -u):$(id -g) --volume $(pwd):/app paulgauthier/aider-full \ --anthropic-api-key $ANTHROPIC_API_KEY \ --model claude-3-5-sonnet-20241022 \ --no-attribute-author \ --no-attribute-committer \ --dark-mode \ $@ } # ---- linting alias hfmt='djlint --indent 2 --reformat ' alias jfmt='js-beautify -s2 -r ' alias llm='python3 -m llm -m claude-3.5-sonnet' dmon(){ docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock:ro --pull=always mrjackwills/oxker } # --- docker dim (){ if [[ $1 == 'jupyter' ]] || [[ $1 == 'poetry' ]] then IMG=$1 echo -e "FROM python:3.11\nRUN pip install $1" | docker build -t $1 -f - . fi } dg () { docker ps | awk '{print $1, $2, $NF}' | grep $1|awk '{print $1}' } dps(){ docker ps --format '{{.ID}}\t{{.Status}}\t{{.Names}}' } dat(){ CMD=${2:-bash} docker exec -it $(dg $1) $CMD } dsh (){ docker run --rm \ -it \ --ulimit core=-1 \ -v /tmp:/tmp \ -v /var/run/docker.sock:/var/run/docker.sock \ -v $PWD:/app \ --workdir /app \ --network host \ --memory 5g \ --cap-add=SYS_PTRACE \ $@ } dlf (){ docker logs -f $(dg $1) } dre (){ docker restart $(dg $1) } dk (){ # When run inside a git project, it will # 1. Find a file called bashrc # 2. Source it # 3. Pass on the remaining arguments to that # # This allows us to do things like: # dk up dev # dk down dev # dk release # # and have all those functions defined inside project code REPOROOT=$(git rev-parse --show-toplevel) FOLDER=actions if [ -d cicd ] then FOLDER=cicd fi ([ ! -z "$REPOROOT" ] && source $REPOROOT/$FOLDER/bashrc 2> /dev/null && $@) } age-backup(){ pwd for KEY in $(ag -l -u age-secret-key |grep -v /bin/) do zip ~/.ssh/age-keys.zip $KEY done } # --- laptop_east (){ DISPLAY=':0' ssh rg.local -v "x2x -east -to :0" } jci () { docker run --rm -it \ -v /tmp:/tmp \ -v $PWD:/app \ -v /var/run/docker.sock:/var/run/docker.sock \ arjoonn/jci python -m jaypore_ci } newsh (){ echo " #!/usr/bin/env bash set -o errexit set -o nounset set -o pipefail # set -o xtrace main() { echo do awesome stuff } (main) " > $1 } kaggle(){ docker run --rm -it -v $PWD:/app --network host gcr.io/kaggle-images/python /bin/bash } # Clean disk free_space(){ docker system prune echo '----------------------------------------------------' sudo du -csh /var/cache/apt sudo apt-get clean sudo apt-get autoremove echo '----------------------------------------------------' sudo journalctl --vacuum-time=3d echo '----------------------------------------------------' # Removes old revisions of snaps # CLOSE ALL SNAPS BEFORE RUNNING THIS du -h /var/lib/snapd/snaps set -eu sudo snap list --all | awk '/disabled/{print $1, $3}' | while read snapname revision; do sudo snap remove "$snapname" --revision="$revision" done } # Listing shortcuts alias ls="ls --color" alias l="ls" alias ll="ls -al" alias la="ls -a" # virtualenv shortcuts p (){ if test -f "Pipfile.lock"; then pipenv shell else if test -f "poetry.lock"; then poetry shell fi fi } alias pidd='pipenv install --deploy --dev' alias pid='pipenv install --deploy' alias t="tmux a || ((sleep 10 && tmux kill-session -t 0) & tmux)" alias a="source env/bin/activate 2> /dev/null || source venv/bin/activate" # git shorcuts git config --global merge.tool diffconflicts git config --global mergetool.diffconflicts.cmd 'diffconflicts vim $BASE $LOCAL $REMOTE $MERGED' git config --global mergetool.diffconflicts.trustExitCode true git config --global mergetool.keepBackup false Gprofile () { case $1 in "mp") git config user.email "arjoonn@midpathsoftware.com" git config user.name "Arjoonn Sharma" ;; "arjoonn") git config user.email "code@arjoonn.com" git config user.name "Arjoonn Sharma" ;; "khushboo") git config user.email "khushboo.garg@midpathsoftware.com" git config user.name "Khushboo Garg" ;; "rg") git config user.email "arjoonn.sharma@resonanzgroup.com" git config user.name "Arjoonn Sharma" ;; esac } Gpipe(){ BRN=${1:-develop} SRC=${2:-origin} DST=${3:-gitea} git checkout $BRN Gsync $SRC git push $DST } Gbclean (){ git checkout ${1:-master} git branch|grep -v '*'|xargs git branch -D } Gfresh (){ REMOTE=${1:-origin} BRANCH=$(git branch|grep \*|awk '{print $2}') TRUNK=${2:-develop} echo "Current: $BRANCH" echo "Trunk : $REMOTE/$TRUNK" git checkout $TRUNK git fetch $REMOTE $TRUNK git reset --hard $REMOTE/$TRUNK git checkout $BRANCH git merge $TRUNK } Gsync (){ REMOTE=${1:-origin} current_branch=$(git branch|grep \*|awk '{print $2}') BRANCH=${2:-$current_branch} echo "Syncing: ${REMOTE}/${BRANCH}" git checkout $BRANCH git fetch $REMOTE git reset --hard $REMOTE/$BRANCH } Gpullup (){ current_branch=$(git branch|grep \*|awk '{print $2}') git checkout develop Gsync git checkout $current_branch git merge develop } minorpatch (){ git checkout master git fetch --prune --prune-tags origin git reset --hard origin/master git tag -l *prod| sort -V|tail -n 5 LAST=$(git tag -l *prod| awk -F- '{print $1}'|sort -V|tail -n 1) NEWV=$(echo $LAST|awk -F. '{print $3}'|python3 -c 'print(int(input())+1)') PRE=$(echo $LAST|awk -F. 'BEGIN { OFS = "." }{print $1,$2}') NEWTAG=$(echo $PRE.$NEWV-prod) echo =================== bold=$(tput bold) normal=$(tput sgr0) echo "Bumping to ${bold}$NEWTAG${normal}" git tag $NEWTAG git log --oneline --decorate=full| head -n5 echo =================== echo "Use this command to push the tag" echo "git push origin $NEWTAG" } nbr (){ prefix=$1_ n_branches=$(git branch -a|grep \/$prefix|grep remotes|awk -F/ '{print $3}'|wc -l) n_branches=$((n_branches+1)) name=$(echo $prefix$n_branches) if git branch | grep -q $name then read -p "$name Exists. Checkout? Crtl-C to stop." git log --no-merges $name ^master git checkout $name else read -p "Continue to create branch $name? Crtl-C to stop." git checkout -b $name fi } alias Gr='git reset HEAD' alias Gb='git branch' alias Ga='git add' alias Gs='git status' alias Gl='git log --oneline' alias Gd='git diff' alias GacP='git add -Av && git commit && git push origin' alias Gc='git commit' alias Gac='git add -Av && git commit' alias Gpu='git push ' alias Gck='git checkout' alias Gck-='git checkout -- .' alias Gckb='git checkout -b' alias Gcl='git clone' Gpu_ (){ # push and set upstream to same name git push --set-upstream $@ origin $(git branch |grep \*|cut -c3-) } Gpl (){ # push and set upstream to same name git pull ${1:-origin} $(git branch |grep \*|cut -c3-) } Gckg (){ git checkout $(git branch | grep $1) } # SSH helpers sshAuthorizedKeys() { while read l; do [[ -n $l && ${l###} = $l ]] && ssh-keygen -l -f /dev/stdin <<<$l; done < .ssh/authorized_keys } #Misc shortcuts dcp (){ scp pds.dell.ubuntu:/tmp/clip /tmp/clip xclip -selection clipboard /tmp/clip } alias dpaste="curl -F 'format=url' -F 'content=<-' https://dpaste.de/api/" alias gv='grep -v' alias bat='upower -i /org/freedesktop/UPower/devices/battery_BAT0|grep percentage' alias cpclip='xclip -selection clipboard' alias wtt='python3 -m worktimething' alias ..='cd ..' alias ..2='cd ../..' alias ..3='cd ../../..' alias ..4='cd ../../../..' alias ..5='cd ../../../..' alias c="cd" alias rf='rm -rf' mkcd() { mkdir $1; cd $1; } alias antlr4='java -jar /usr/local/lib/antlr-4.7.2-complete.jar' alias grun='java org.antlr.v4.gui.TestRig' # ExPORTS export EDITOR='vim' export LANG="en_US.UTF-8" # bash history shopt -s cmdhist shopt -s histappend # https://superuser.com/a/664061 export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$"\n"}history -a; history -c; history -r" export HISTFILESIZE= export HISTSIZE= export HISTFILE=~/.bash_eternal_history export HISTTIMEFORMAT="[%F %T] " export HISTCONTROL=ignoredups # useful tools if ! command -v vim > /dev/null then echo "You don't have vim." # sudo apt install vim-gnome fi if [ ! -d $HOME/.vim ]; then if [ -d $HOME/arjoonncom ]; then ln -s ~/arjoonncom/website/content/static/vimrc ~/.vimrc else curl https://www.arjoonn.com/static/vimrc >> ~/.vimrc fi git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim vim +PluginInstall +qall fi ps1_exit_state (){ code=$? if [ ! "$code" -eq "0" ]; then echo "$code " else echo "" fi } ps1_git_info (){ lbrace="⦑·" rbrace="·⦒" lbrace="[" rbrace="]" if git status 2> /dev/null 1>&2 then bname=$(git branch|grep '*'|awk '{print $2}'|tr -d '\n') if [[ $bname == 'master' ]] || [[ $bname == 'production' ]] then echo -e "\033[91m"|tr -d '\n' fi echo "$lbrace"|tr -d '\n' git branch|grep '*'|awk '{print $2}'|tr -d '\n' if ! git status | grep 'nothing to commit' > /dev/null then echo "|"|tr -d '\n' git status -s|awk '{print $1}'|sort|uniq|tr -d '\n'|sed 's/??/?/g' fi echo ' | ' | tr -d '\n' git config user.email |tr -d '\n' echo "$rbrace "|tr -d '\n' if [[ $bname == 'master' ]] || [[ $bname == 'production' ]] then echo -e "\033[0m"|tr -d '\n' fi fi } ps1_end_symbol (){ if test "${PWD##/home/arjoonnmp}" != "${PWD}" then echo "🐼" return fi if test "${PWD##/home/arjoonn}" != "${PWD}" then echo "🔥" return fi echo "🌀" } ps1_prompt (){ echo -e "$(date +'%H:%M')\n $(ps1_end_symbol) " } ps1_path (){ pwd|python3 -c "x=(''.join(i[0] for i in input().split('/') if i.strip())[:-1]); print('~' if len(x)<2 else '~'+x[2:], end='.')" echo ${PWD##*/} } PS1='$(ps1_exit_state)$(ps1_git_info)$(ps1_path) $(ps1_prompt)' # PS1='$(ps1_exit_state)\e[33;1m$(ps1_git_info)\e[0m$(ps1_path)\e[0m $(ps1_prompt)' bind 'TAB:menu-complete' export GEM_HOME="$HOME/gems" (ssh-add ~/.ssh/id_nitro 2&> /dev/null) alias kubectl="minikube kubectl --"