# 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"
gli() {
# Configuration
GITLAB_URL="${GITLAB_URL:-https://gitlab.smaac.in}"
GITLAB_TOKEN="${SMAAC_GITLAB_TOKEN}"
PROJECT_ID="3"
# Check if required environment variables are set
if [ -z "$GITLAB_TOKEN" ]; then
echo "Error: GITLAB_TOKEN environment variable not set"
echo "Set it with: export GITLAB_TOKEN='your_personal_access_token'"
return 1
fi
if [ -z "$PROJECT_ID" ]; then
echo "Error: GITLAB_PROJECT_ID environment variable not set"
echo "Set it with: export GITLAB_PROJECT_ID='your_project_id'"
return 1
fi
# Create temporary file
TEMP_FILE=$(mktemp /tmp/gitlab-issue-XXXXXX.md)
# Pre-populate with template
cat > "$TEMP_FILE" << 'EOF'
# Issue Title Here
- [ ] tasks
/label ~"effort:dev::1h"
/due wednesday
/label ~Midpath
/label ~"Type::maintenance ๐ฆบ"
/label ~"Type::enhancement โจ"
/label ~"Type::operations ๐ ๏ธ"
/label ~"Type::Bug ๐"
/label ~"Importance::Medium"
/label ~"Importance::Low"
/label ~"Importance::High"
/label ~"Stage::To be done"
/label ~"Developer::Abish"
/label ~"Tester::Rashmi"
EOF
# Open vim
vim "$TEMP_FILE"
# Check if file was saved (not empty and exists)
if [ ! -f "$TEMP_FILE" ] || [ ! -s "$TEMP_FILE" ]; then
echo "โ Cancelled: No content provided"
rm -f "$TEMP_FILE" 2>/dev/null
return 1
fi
# Extract title (first line) and description (rest)
TITLE=$(head -n1 "$TEMP_FILE" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
DESCRIPTION=$(tail -n+2 "$TEMP_FILE" | sed ':a;N;$!ba;s/\n/\\n/g' | sed 's/"/\\"/g')
# Check if title is provided
if [ -z "$TITLE" ] || [ "$TITLE" = "Issue Title Here" ]; then
echo "โ Cancelled: No title provided or title unchanged"
rm -f "$TEMP_FILE"
return 1
fi
echo ""
echo "Creating issue..."
echo "Title: $TITLE"
echo "Project: $PROJECT_ID"
# Create the issue using GitLab API
response=$(curl -s -X POST \
-H "PRIVATE-TOKEN: $GITLAB_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"title\": \"$TITLE\",
\"description\": \"$DESCRIPTION\"
}" \
"$GITLAB_URL/api/v4/projects/$PROJECT_ID/issues")
# Clean up temp file
rm -f "$TEMP_FILE"
# Check if the request was successful
if echo "$response" | grep -q '"iid"'; then
issue_iid=$(echo "$response" | grep -o '"iid":[0-9]*' | cut -d':' -f2)
web_url=$(echo "$response" | grep -o '"web_url":"[^"]*' | cut -d'"' -f4)
echo ""
echo "โ
Issue #$issue_iid created successfully!"
echo "๐ Title: $TITLE"
echo "๐ URL: $web_url"
# Copy URL to clipboard if available
if command -v xclip >/dev/null 2>&1; then
echo "$web_url" | xclip -selection clipboard
echo "๐ URL copied to clipboard"
elif command -v pbcopy >/dev/null 2>&1; then
echo "$web_url" | pbcopy
echo "๐ URL copied to clipboard"
fi
else
echo ""
echo "โ Failed to create issue"
echo "Response: $response"
return 1
fi
}
gpt(){
curl -s -X POST --data-binary "Return one line answers when possible. $1" 'http://localhost:9002'
echo
}
aider(){
#--model claude-opus-4-20250514 \
(docker pull paulgauthier/aider 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-opus-4-20250514 \
--no-attribute-author \
--no-attribute-committer \
--watch-files \
--no-show-release-notes \
--no-analytics \
--no-auto-lint \
--no-auto-test \
--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 \
$@
}
dbl (){
NAME=$(pwd | awk -F\/ '{print $NF}')
docker build -t $NAME .
}
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 && $@)
}
dkoff(){
touch ~/.keep_dk_off
sudo systemctl disable --now docker.service docker.socket
}
dkon(){
sudo systemctl enable --now docker.service docker.socket
rm ~/.keep_dk_off
}
if [ -f "~/.keep_dk_off" ]; then
dkoff
fi
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)