# don't need to do this # /etc/bash.bashrc # simple function to output yay or nay based on last status code # have to include it directly in PS1 so it reads the right status code # PROMPT_COMMAND can't see it echo_last_status() { if [ $? = 0 ]; then echo "👌" else echo "👎" fi # newlines are not visible } # git clone git@github.com:jimeh/git-aware-prompt ~/.bash/git-aware-prompt git_branch= git_dirty= if [ -d ~/.bash/git-aware-prompt ]; then source ~/.bash/git-aware-prompt/prompt.sh fi if [ "$EUID" -ne 0 ]; then if [ "$color_prompt" = yes ]; then ps1_folder='\e[32m[\w] \e[1;34m$git_branch\e[31m$git_dirty' else ps1_folder='[w] $git_branch$git_dirty' fi fi PS1='$(echo_last_status)\n'$ps1_shelllevel$ps1_user$ps1_folder$ps1_prompt # if [[ "$TERM" == "xterm-256color" && "$SHLVL" == "1" ]]; then # echo "" # curl --silent --max-time 2 https://wttr.in/lincoln,uk?0Q # if [[ $(which tailscale) != "" ]]; then # expiryEpoch=$(date -d $(tailscale status --json | jq -r '.Self.KeyExpiry') +%s) # nowEpoch=$(date +%s) # if [[ $(($expiryEpoch - $nowEpoch)) -lt $((86400 * 3)) ]]; then # echo -e "tailscale key expiring soon, time to \e[38;5;208mtailscale up --force-reauth\e[0m but not over ssh, obviously" # fi # fi # fi # lol alias nano='vim' # alias bashphp='docker exec -it -w "$PWD" phpfpm bash' # alias bashnode='bash ~/containers/nodejs/interactive.sh' # alias bashgolang='bash ~/containers/golang/interactive.sh' # alias bashruby='bash ~/containers/ruby/interactive.sh' # alias bashpython='bash ~/containers/python/interactive.sh' function git { if [[ "$1" == "clone" && "$@" != *"--help"* ]]; then # I prefer to not include file permissions when cloning # unfortunately this is more involved than just the below # command git clone --config core.filemode=false "$@" curdir="$(pwd)" argsarray=($(echo $@ | tr " " "\n")) lastarg=${argsarray[-1]} penultimatearg=${argsarray[-2]} # if the penultimate arg contains @ or :// then it must be the repo url if ! case $penultimatearg in *"@"* | *"://"*) false;; esac; then newdir="$lastarg" else newdir="$(basename $lastarg .git)" if case $penultimatearg in *":"*) false;; esac; then newdir=${newdir#*:} fi fi # this original way which doesn't support args when clone'ing #if [ -z "$3" ]; then # newdir="$(basename $2 .git)" #else # newdir="$3" #fi shift 1 command git clone "$@" || return 1 cd $newdir #case $@ in # *"workgithubname"* | *"WorkGithubName"* | *"othercompanyname"*) # command git config user.email me@work.com && echo "set user for work boss" # ;; # *"personalgithubname"* | *"gist.github.com"*) # command git config user.email me@home.com && echo "set user for personal boss" # ;; # *) # echo "whoareyou" # ;; #esac command git config --unset core.filemode && echo "removed core.filemode setting boss" cd $curdir elif [[ "$1" == "branch" && "$@" != *"--help"* && "$@" != *" -r"* && -s "$2" && -z "$3" ]]; then if [[ "$2" == "--random" ]]; then command git fetch --all; while true; do name=$RANDOM; if [ -z "$(command git show-ref refs/heads/$name)" ]; then command git checkout -b $name; break; fi; done; else shift 1 echo "switching to checkout..." command git checkout -b "$@" || command git checkout "$@" fi else command git "$@" fi } alias g=git complete -F _complete_alias g alias n=nautilus function docker { if [[ "$1" == "stop-and-rm" ]]; then shift 1 command docker stop "$@" command docker rm "$@" elif [[ "$1" == "login-to-github" ]]; then echo 'ghp_abcd' | docker login ghcr.io -u youruser --password-stdin else command docker "$@" fi } alias d=docker complete -F _complete_alias d # aliases let you put things after the command if you want # i.e. get familiar with the flags but type way fewer characters # e.g. dcb --no-cache -> rebuild the images without cache # e.g. dcu -d -> dc up and detach/background it # e.g. dce app bash -> dc exec bash in the service # e.g. dcd -v -> dc down and clear volumes too export DOCKER_BUILDKIT=1 alias dc="docker-compose" #alias dcb="docker-compose build --parallel" alias dcb="docker-compose build" alias dcd="docker-compose down" alias dcu="docker-compose up" #alias dce="docker-compose exec --user $(id -u):$(id -g) --env HOME=/tmp" alias dce="docker-compose exec" alias dceanrb="dce app npm run build" alias dceanrd="dce app npm run dev" alias dceanrw="dce app npm run watch" alias dceapat="dce app php artisan tinker" alias dceapa="dce app php artisan" alias dceact="dce app composer test" alias dceaca="dce app composer analyse" alias dcetct="dce testapp composer test" alias dcetca="dce testapp composer analyse" alias dcetact="dce test-app composer test" # persisting the changes you've made to your container # is a terrible idea and yet here it is function dcc { if [ "$#" -ne "1" ]; then echo "Precisely one argument required" return 1 fi CONTAINER=$(dc images | grep "_$1 " | awk '{print $1;}') TAGNAME=$(dc images | grep "_app " | awk '{print $2;}') TAGVERSION=$(dc images | grep "_app " | awk '{print $3;}') if [ "$CONTAINER" = "" ] || [ "$TAGNAME" = "" ] || [ "$TAGVERSION" = "" ]; then echo "Unable to figure out what to do" echo "you will need to dcu -d again if you have already run this command" return 1 fi COMMAND="docker commit $CONTAINER $TAGNAME:$TAGVERSION" echo $COMMAND eval $COMMAND } # function k8sprod { # bash --rcfile ~/.bashrc.k8s # } alias tf="terraform"