Files
handy_scripts/addons.sh
2022-11-08 11:52:14 -05:00

49 lines
1.5 KiB
Bash

# prompt no
prn(){
read -n1 -p "$1 (y/N)" yn; if [[ $yn != [Yy] ]]; then printf '\naborted\n'; return 1; else return 0; fi
}
# prompt yes
pry(){
read -n1 -p "$1 (Y/n)" yn; if [[ $yn != [Nn] ]]; then return 0; else printf '\naborted\n'; return 1; fi
}
# find project
fprj(){
find /cygdrive/p/project_notes/. -type d -maxdepth 1 -iname "*$1*" | grep -oP '(?<=\/)([0-9]+).*'
}
# search project
sprj(){
if [[ -z $2 ]]; then grep -Ri $1 /cygdrive/p/project_notes/* --include="*.*"
else grep -Ri $1 /cygdrive/p/project_notes/* --include="*.$2"
fi
}
# new project
function new(){
prjroot="/cygdrive/p/project_notes/"
winprjroot="p:/project_notes/"
editor="/cygdrive/c/Program Files/Sublime\ Text/subl.exe"
if [[ -z $1 ]]; then echo 'i need the project name, bae'; exit 1; else prjname=$(echo $1|sed -e 's/ /-/g'); fi
lastnum=$(find $prjroot. -type d -maxdepth 1 -iname "*[0-9]*" | grep -oP '(?<=\/)([0-9]+)(?=\.)' | sort | tail -1)
prjnum=$(echo $lastnum | awk -F, '{printf("%04d",($lastnum".")+1)}')
prjname="$prjnum.$prjname"
mkdir -p $prjroot$prjname || echo "cannot mkdir '$prjroot$prjname'" && exit 1
touch $prjroot$prjname/$prjname.txt && $editor $winprjroot$prjname/$prjname.txt
if [[ -f .git ]]; then git branch -b $prjname; else echo "no '.git' found"; fi
}
# git new branch
function gnb(){
git branch -b $1
}
# git commit quick
function gcq(){
if [[ -z $1 ]]; then msg="$(date +%F\ %T)"; else msg=$1; fi
git commit -am "$msg" && read -n1 -p "push? [Y/n] " reply; if [[ $reply != [Nn] ]]; then git push; fi
}
alias gs='git status'