| @@ -28,7 +28,18 @@ export AWS_PROFILE=k8s | |||
| 28 | 28 | export AWS_SDK_LOAD_CONFIG=1 | |
| 29 | 29 | export KOPS_STATE_STORE=your-kops-state-store | |
| 30 | 30 | ||
| 31 | - | function kubectl { | |
| 31 | + | source <(kubectl completion bash) | |
| 32 | + | ||
| 33 | + | # have to manually install other bash completions | |
| 34 | + | # cd $(pkg-config --variable=completionsdir bash-completion) | |
| 35 | + | # curl https://raw.githubusercontent.com/ahmetb/kubectx/master/completion/kubectx.bash | sudo tee kubectx | |
| 36 | + | # curl https://raw.githubusercontent.com/ahmetb/kubectx/master/completion/kubens.bash | sudo tee kubens | |
| 37 | + | ||
| 38 | + | alias k=kubectl | |
| 39 | + | complete -F __start_kubectl k | |
| 40 | + | #complete -F _complete_alias k | |
| 41 | + | ||
| 42 | + | function qk { | |
| 32 | 43 | if [[ "$1" == "token" ]]; then | |
| 33 | 44 | command aws-iam-authenticator token -i your.k8s.cluster -r arn:aws:iam::012345678910:role/OrganizationAccountAccessRole | jq -r .status.token | pbcopy | |
| 34 | 45 | elif [[ "$1" == "dashboard" ]]; then | |
| @@ -54,6 +65,3 @@ function kubectl { | |||
| 54 | 65 | command kubectl "$@" | |
| 55 | 66 | fi | |
| 56 | 67 | } | |
| 57 | - | ||
| 58 | - | alias k=kubectl | |
| 59 | - | complete -F _complete_alias k | |
willpower232 / bash.bashrc
Last active 1 month ago
I am making my .bashrc portable as inspired by this https://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html
Will Power revised this gist 6 years ago · d89b959
1 file changed, 12 insertions, 4 deletions
William Hall revised this gist 6 years ago · cda0d0e
3 files changed, 168 insertions, 34 deletions
| @@ -1,9 +1,4 @@ | |||
| 1 | - | # git clone git@github.com:jimeh/git-aware-prompt ~/.bash/git-aware-prompt | |
| 2 | - | git_branch= | |
| 3 | - | git_dirty= | |
| 4 | - | if [ -d ~/.bash/git-aware-prompt ]; then | |
| 5 | - | source ~/.bash/git-aware-prompt/prompt.sh | |
| 6 | - | fi | |
| 1 | + | #### Set prompt basics #### | |
| 7 | 2 | ||
| 8 | 3 | # set variable identifying the chroot you work in (used in the prompt below) | |
| 9 | 4 | if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then | |
| @@ -31,25 +26,36 @@ if [ -n "$force_color_prompt" ]; then | |||
| 31 | 26 | fi | |
| 32 | 27 | fi | |
| 33 | 28 | ||
| 29 | + | #### Set initial prompt #### | |
| 30 | + | ||
| 31 | + | ps1_shelllevel='${debian_chroot:+($debian_chroot)}($SHLVL) ' | |
| 32 | + | ||
| 34 | 33 | if [ "$color_prompt" = yes ]; then | |
| 34 | + | ps1_user='\u@\h {\A} ' | |
| 35 | + | ||
| 36 | + | # have to remember to wrap the 0-width characters on the line of the prompt in \[ and \] | |
| 35 | 37 | if [ "$EUID" -ne 0 ]; then | |
| 36 | - | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[32m[\w] \e[1;34m$git_branch\e[31m$git_dirty\e[0m\n$ ' | |
| 38 | + | ps1_folder='\e[32m[\w]' | |
| 39 | + | ps1_prompt='\n\[\e[0m\]$ ' | |
| 37 | 40 | else | |
| 38 | - | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[31m[\w]\e[0m\n# ' | |
| 41 | + | ps1_folder='\e[31m[\w]' | |
| 42 | + | ps1_prompt='\n\[\e[0m\]# ' | |
| 39 | 43 | fi | |
| 40 | - | ||
| 41 | - | # some terminals need to know the previous non-printing (colour changing) characters have finished | |
| 42 | - | # otherwise backspace can delete a prompt because it doesn't know where to start | |
| 43 | - | # ref https://unix.stackexchange.com/a/150493 | |
| 44 | - | #PS1="$PS1\]" | |
| 45 | 44 | else | |
| 45 | + | ps1_user='u@h {a} ' | |
| 46 | + | ps1_folder='[w]' | |
| 47 | + | ||
| 46 | 48 | if [ "$EUID" -ne 0 ]; then | |
| 47 | - | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w] $git_branch$git_dirty\n$ ' | |
| 49 | + | ps1_prompt='\n$ ' | |
| 48 | 50 | else | |
| 49 | - | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w]\n# ' | |
| 51 | + | ps1_prompt='\n# ' | |
| 50 | 52 | fi | |
| 51 | 53 | fi | |
| 52 | - | unset color_prompt force_color_prompt | |
| 54 | + | ||
| 55 | + | PS1=$ps1_shelllevel$ps1_user$ps1_folder$ps1_prompt | |
| 56 | + | ||
| 57 | + | # don't unset these so they can be used later | |
| 58 | + | #unset color_prompt force_color_prompt | |
| 53 | 59 | ||
| 54 | 60 | # not sure what this bit does | |
| 55 | 61 | #case "$TERM" in | |
| @@ -59,7 +65,8 @@ unset color_prompt force_color_prompt | |||
| 59 | 65 | # ;; | |
| 60 | 66 | #esac | |
| 61 | 67 | ||
| 62 | - | # enable color support of ls and also add handy aliases | |
| 68 | + | #### Colour support #### | |
| 69 | + | ||
| 63 | 70 | if [ -x /usr/bin/dircolors ]; then | |
| 64 | 71 | test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" | |
| 65 | 72 | alias ls='ls --color=auto' | |
| @@ -74,13 +81,22 @@ if [ -x /usr/bin/dircolors ]; then | |||
| 74 | 81 | alias ip='ip -c' | |
| 75 | 82 | fi | |
| 76 | 83 | ||
| 84 | + | #### Aliases for all #### | |
| 85 | + | ||
| 86 | + | # alias commands that prefix commands | |
| 87 | + | # so they can prefix your aliases | |
| 88 | + | # https://askubuntu.com/a/22043 | |
| 89 | + | alias sudo='sudo ' | |
| 90 | + | alias watch='watch ' | |
| 91 | + | ||
| 92 | + | alias vim='vim -i NONE' | |
| 77 | 93 | alias nano='nano --nowrap --smooth -T 4' | |
| 78 | 94 | alias plz='sudo ' | |
| 79 | 95 | alias dammit='sudo !!' | |
| 80 | 96 | ||
| 81 | 97 | # stop yourself from breaking the server by accident | |
| 82 | - | alias mv='mv -i' | |
| 83 | - | alias cp='cp -i' | |
| 98 | + | alias mv='mv -i' | |
| 99 | + | alias cp='cp -i' | |
| 84 | 100 | alias ln='ln -i' | |
| 85 | 101 | alias rm='rm -I --preserve-root' | |
| 86 | 102 | alias chown='chown --preserve-root' | |
| @@ -98,21 +114,14 @@ if [ "$(uname)" == "Darwin" ]; then | |||
| 98 | 114 | elif grep -q Microsoft /proc/version; then | |
| 99 | 115 | # route error to /dev/null because thanks microsoft | |
| 100 | 116 | alias pbcopy='clip.exe > /dev/null 2>&1' | |
| 117 | + | # todo: pbpaste in wsl | |
| 101 | 118 | else | |
| 102 | 119 | # install xclip through apt first | |
| 103 | 120 | alias pbcopy='xclip -selection clipboard' | |
| 104 | 121 | alias pbpaste='xclip -selection clipboard -o' | |
| 105 | 122 | fi | |
| 106 | 123 | ||
| 107 | - | # thanks @jamesdoc | |
| 108 | - | alias e-thumbsup="printf \"👍\" | pbcopy && echo \"👍 copied to the clipboard\"" | |
| 109 | - | alias e-pointup="printf \"👆\" | pbcopy && echo \"👆 copied to the clipboard\"" | |
| 110 | - | alias e-pointdown="printf \"👇\" | pbcopy && echo \"👇 copied to the clipboard\"" | |
| 111 | - | alias e-rocket="printf \"🚀\" | pbcopy && echo \"🚀 copied to the clipboard\"" | |
| 112 | - | alias e-tada="printf \"🎉\" | pbcopy && echo \"🎉 copied to the clipboard\"" | |
| 113 | - | alias e-lightning="printf \"⚡\" | pbcopy && echo \"⚡ copied to the clipboard\"" | |
| 114 | - | alias shruggie="printf \"¯\_(ツ)_/¯\" | pbcopy && echo \"¯\_(ツ)_/¯ copied to clipboard\"" | |
| 115 | - | ||
| 124 | + | # inspired by @jamesdoc https://twitter.com/jamesdoc/status/902829327187931137 | |
| 116 | 125 | # ref https://github.com/dannyfritz/commit-message-emoji | |
| 117 | 126 | alias gc-InitialCommit="printf \"🎉\" | pbcopy && pbpaste && echo \"\"" | |
| 118 | 127 | alias gc-VersionTag="printf \"🔖\" | pbcopy && pbpaste && echo \"\"" | |
| @@ -141,6 +150,8 @@ if [ -x /usr/bin/cmatrix ]; then | |||
| 141 | 150 | alias etm="cmatrix -a -b -s -C cyan" | |
| 142 | 151 | fi | |
| 143 | 152 | ||
| 153 | + | #### Final settings for all #### | |
| 154 | + | ||
| 144 | 155 | # this is needed to enter the passphrase when attempting to gpg-sign git commits | |
| 145 | 156 | #export GPG_TTY=$(tty) | |
| 146 | 157 | ||
| @@ -155,6 +166,7 @@ fi | |||
| 155 | 166 | #HISTCONTROL=ignoreboth | |
| 156 | 167 | ||
| 157 | 168 | # Debian doesn't have bash-completion by default so you need to apt install bash-completion and add the below | |
| 169 | + | # also don't forget about https://github.com/cykerway/complete-alias | |
| 158 | 170 | #if [ -f /etc/bash_completion ]; then | |
| 159 | - | # . /etc/bash_completion | |
| 160 | - | #fi | |
| 171 | + | # . /etc/bash_completion | |
| 172 | + | #fi | |
| @@ -1,15 +1,64 @@ | |||
| 1 | - | . /etc/bash.bashrc | |
| 1 | + | # don't need to do this | |
| 2 | + | # /etc/bash.bashrc | |
| 2 | 3 | ||
| 3 | - | # https://askubuntu.com/a/22043 | |
| 4 | - | alias sudo='sudo ' | |
| 4 | + | # simple function to output yay or nay based on last status code | |
| 5 | + | # have to include it directly in PS1 so it reads the right status code | |
| 6 | + | echo_last_status() { | |
| 7 | + | if [ $? = 0 ]; then | |
| 8 | + | echo "👌" | |
| 9 | + | else | |
| 10 | + | echo "👎" | |
| 11 | + | fi | |
| 12 | + | # can't output a newline | |
| 13 | + | } | |
| 14 | + | ||
| 15 | + | # git clone git@github.com:jimeh/git-aware-prompt ~/.bash/git-aware-prompt | |
| 16 | + | git_branch= | |
| 17 | + | git_dirty= | |
| 18 | + | if [ -d ~/.bash/git-aware-prompt ]; then | |
| 19 | + | source ~/.bash/git-aware-prompt/prompt.sh | |
| 20 | + | fi | |
| 21 | + | ||
| 22 | + | if [ "$EUID" -ne 0 ]; then | |
| 23 | + | if [ "$color_prompt" = yes ]; then | |
| 24 | + | ps1_folder='\e[32m[\w] \e[1;34m$git_branch\e[31m$git_dirty' | |
| 25 | + | else | |
| 26 | + | ps1_folder='[w] $git_branch$git_dirty' | |
| 27 | + | fi | |
| 28 | + | fi | |
| 29 | + | ||
| 30 | + | PS1='$(echo_last_status)\n'$ps1_shelllevel$ps1_user$ps1_folder$ps1_prompt | |
| 5 | 31 | ||
| 6 | 32 | # lol | |
| 7 | 33 | alias nano='vim' | |
| 8 | 34 | ||
| 35 | + | # alias bashphp='docker exec -it -w "$PWD" phpfpm bash' | |
| 36 | + | # alias bashnode='bash ~/containers/nodejs/interactive.sh' | |
| 37 | + | # alias bashruby='bash ~/containers/ruby/interactive.sh' | |
| 38 | + | # alias bashpython='bash ~/containers/python/interactive.sh' | |
| 39 | + | ||
| 9 | 40 | function git { | |
| 10 | 41 | if [[ "$1" == "clone" && "$@" != *"--help"* ]]; then | |
| 42 | + | ||
| 43 | + | # I prefer to not include file permissions when cloning | |
| 44 | + | # unfortunately this is more involved than just the below | |
| 45 | + | # command git clone --config core.filemode=false "$@" | |
| 46 | + | ||
| 47 | + | curdir="$(pwd)" | |
| 48 | + | ||
| 49 | + | if [ -z "$3" ]; then | |
| 50 | + | newdir="$(basename $2 .git)" | |
| 51 | + | else | |
| 52 | + | newdir="$3" | |
| 53 | + | fi | |
| 54 | + | ||
| 11 | 55 | shift 1 | |
| 12 | - | command git clone --config core.filemode=false "$@" | |
| 56 | + | command git clone "$@" | |
| 57 | + | cd $newdir | |
| 58 | + | command git config --unset core.filemode | |
| 59 | + | cd $curdir | |
| 60 | + | echo "removed core.filemode setting boss" | |
| 61 | + | ||
| 13 | 62 | elif [[ "$1" == "branch" && "$@" != *"--help"* ]]; then | |
| 14 | 63 | shift 1 | |
| 15 | 64 | command git checkout -b "$@" | |
| @@ -18,6 +67,10 @@ function git { | |||
| 18 | 67 | fi | |
| 19 | 68 | } | |
| 20 | 69 | ||
| 70 | + | alias g=git | |
| 71 | + | complete -F _complete_alias g | |
| 72 | + | alias n=nautilus | |
| 73 | + | ||
| 21 | 74 | function docker { | |
| 22 | 75 | if [[ "$1" == "stop-and-rm" ]]; then | |
| 23 | 76 | shift 1 | |
| @@ -28,15 +81,20 @@ function docker { | |||
| 28 | 81 | fi | |
| 29 | 82 | } | |
| 30 | 83 | ||
| 84 | + | alias d=docker | |
| 85 | + | complete -F _complete_alias d | |
| 86 | + | ||
| 31 | 87 | # aliases let you put things after the command if you want | |
| 32 | 88 | # i.e. get familiar with the flags but type way fewer characters | |
| 33 | 89 | # e.g. dc build --no-cache -> rebuild the images without cache | |
| 34 | 90 | # e.g. dcu -d -> dc up and detach/background it | |
| 35 | 91 | # e.g. dce app bash -> dc exec bash in the service | |
| 36 | 92 | # e.g. dcd -v -> dc down and clear volumes too | |
| 93 | + | ||
| 37 | 94 | alias dc=docker-compose | |
| 38 | 95 | alias dcd="docker-compose down" | |
| 39 | 96 | alias dcu="docker-compose up" | |
| 97 | + | #alias dce="docker-compose exec --user $(id -u):$(id -g) --env HOME=/tmp" | |
| 40 | 98 | alias dce="docker-compose exec" | |
| 41 | 99 | ||
| 42 | 100 | # persisting the changes you've made to your container | |
| @@ -53,6 +111,7 @@ function dcc { | |||
| 53 | 111 | ||
| 54 | 112 | if [ "$CONTAINER" = "" ] || [ "$TAGNAME" = "" ] || [ "$TAGVERSION" = "" ]; then | |
| 55 | 113 | echo "Unable to figure out what to do" | |
| 114 | + | echo "you will need to dcu -d again if you have already run this command" | |
| 56 | 115 | return 1 | |
| 57 | 116 | fi | |
| 58 | 117 | ||
| @@ -60,3 +119,7 @@ function dcc { | |||
| 60 | 119 | echo $COMMAND | |
| 61 | 120 | eval $COMMAND | |
| 62 | 121 | } | |
| 122 | + | ||
| 123 | + | #function k8sprod { | |
| 124 | + | # bash --rcfile ~/.bashrc.k8s | |
| 125 | + | #} | |
| @@ -0,0 +1,59 @@ | |||
| 1 | + | if [ -f "$HOME/.bashrc" ]; then | |
| 2 | + | . "$HOME/.bashrc" | |
| 3 | + | fi | |
| 4 | + | ||
| 5 | + | cd ~/gitrepos/k8s-configs | |
| 6 | + | ||
| 7 | + | # https://github.com/ahmetb/kubectx | |
| 8 | + | k8s_context= | |
| 9 | + | k8s_namespace= | |
| 10 | + | find_k8s() { | |
| 11 | + | k8s_context="$(kubectx -c)" | |
| 12 | + | k8s_namespace="$(kubens -c)" | |
| 13 | + | } | |
| 14 | + | ||
| 15 | + | PROMPT_COMMAND="find_k8s; $PROMPT_COMMAND" | |
| 16 | + | ||
| 17 | + | if [ "$EUID" -ne 0 ]; then | |
| 18 | + | if [ "$color_prompt" = yes ]; then | |
| 19 | + | ps1_folder='\e[32m[\w] \e[1;34m$k8s_context/$k8s_namespace' | |
| 20 | + | else | |
| 21 | + | ps1_folder='[w] $k8s_context/$k8s_namespace' | |
| 22 | + | fi | |
| 23 | + | fi | |
| 24 | + | ||
| 25 | + | PS1='$(echo_last_status)\n'$ps1_shelllevel$ps1_user$ps1_folder$ps1_prompt | |
| 26 | + | ||
| 27 | + | export AWS_PROFILE=k8s | |
| 28 | + | export AWS_SDK_LOAD_CONFIG=1 | |
| 29 | + | export KOPS_STATE_STORE=your-kops-state-store | |
| 30 | + | ||
| 31 | + | function kubectl { | |
| 32 | + | if [[ "$1" == "token" ]]; then | |
| 33 | + | command aws-iam-authenticator token -i your.k8s.cluster -r arn:aws:iam::012345678910:role/OrganizationAccountAccessRole | jq -r .status.token | pbcopy | |
| 34 | + | elif [[ "$1" == "dashboard" ]]; then | |
| 35 | + | echo "Copying token to clipboard..." | |
| 36 | + | qk token | |
| 37 | + | echo "Done" | |
| 38 | + | echo "When running, visit http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/" | |
| 39 | + | k proxy | |
| 40 | + | elif [[ "$1" == "watch" ]]; then | |
| 41 | + | shift 1 | |
| 42 | + | if [[ "$1" == "get" ]]; then | |
| 43 | + | shift 1 | |
| 44 | + | k get --watch "$@" | |
| 45 | + | else | |
| 46 | + | command watch -n 1 kubectl "$@" | |
| 47 | + | fi | |
| 48 | + | elif [[ "$1" == "podexec" ]]; then | |
| 49 | + | shift 1 | |
| 50 | + | firstpod="$(k get pods --output=jsonpath="{.items[0].metadata.name}" | head -1)" | |
| 51 | + | echo "Running in $firstpod" | |
| 52 | + | k exec -it $firstpod "$@" | |
| 53 | + | else | |
| 54 | + | command kubectl "$@" | |
| 55 | + | fi | |
| 56 | + | } | |
| 57 | + | ||
| 58 | + | alias k=kubectl | |
| 59 | + | complete -F _complete_alias k | |
Will Power revised this gist 6 years ago · 39fae94
1 file changed, 3 insertions
| @@ -69,6 +69,9 @@ if [ -x /usr/bin/dircolors ]; then | |||
| 69 | 69 | alias grep='grep --color=auto' | |
| 70 | 70 | alias fgrep='fgrep --color=auto' | |
| 71 | 71 | alias egrep='egrep --color=auto' | |
| 72 | + | ||
| 73 | + | # may be --color=auto in some versions... | |
| 74 | + | alias ip='ip -c' | |
| 72 | 75 | fi | |
| 73 | 76 | ||
| 74 | 77 | alias nano='nano --nowrap --smooth -T 4' | |
William Hall revised this gist 7 years ago · fd88c20
3 files changed, 214 insertions, 117 deletions
| @@ -0,0 +1,157 @@ | |||
| 1 | + | # git clone git@github.com:jimeh/git-aware-prompt ~/.bash/git-aware-prompt | |
| 2 | + | git_branch= | |
| 3 | + | git_dirty= | |
| 4 | + | if [ -d ~/.bash/git-aware-prompt ]; then | |
| 5 | + | source ~/.bash/git-aware-prompt/prompt.sh | |
| 6 | + | fi | |
| 7 | + | ||
| 8 | + | # set variable identifying the chroot you work in (used in the prompt below) | |
| 9 | + | if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then | |
| 10 | + | debian_chroot=$(cat /etc/debian_chroot) | |
| 11 | + | fi | |
| 12 | + | ||
| 13 | + | # set a fancy prompt (non-color, unless we know we "want" color) | |
| 14 | + | case "$TERM" in | |
| 15 | + | xterm-color) color_prompt=yes;; | |
| 16 | + | esac | |
| 17 | + | ||
| 18 | + | # uncomment for a colored prompt, if the terminal has the capability; turned | |
| 19 | + | # off by default to not distract the user: the focus in a terminal window | |
| 20 | + | # should be on the output of commands, not on the prompt | |
| 21 | + | force_color_prompt=yes | |
| 22 | + | ||
| 23 | + | if [ -n "$force_color_prompt" ]; then | |
| 24 | + | if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then | |
| 25 | + | # We have color support; assume it's compliant with Ecma-48 | |
| 26 | + | # (ISO/IEC-6429). (Lack of such support is extremely rare, and such | |
| 27 | + | # a case would tend to support setf rather than setaf.) | |
| 28 | + | color_prompt=yes | |
| 29 | + | else | |
| 30 | + | color_prompt= | |
| 31 | + | fi | |
| 32 | + | fi | |
| 33 | + | ||
| 34 | + | if [ "$color_prompt" = yes ]; then | |
| 35 | + | if [ "$EUID" -ne 0 ]; then | |
| 36 | + | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[32m[\w] \e[1;34m$git_branch\e[31m$git_dirty\e[0m\n$ ' | |
| 37 | + | else | |
| 38 | + | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[31m[\w]\e[0m\n# ' | |
| 39 | + | fi | |
| 40 | + | ||
| 41 | + | # some terminals need to know the previous non-printing (colour changing) characters have finished | |
| 42 | + | # otherwise backspace can delete a prompt because it doesn't know where to start | |
| 43 | + | # ref https://unix.stackexchange.com/a/150493 | |
| 44 | + | #PS1="$PS1\]" | |
| 45 | + | else | |
| 46 | + | if [ "$EUID" -ne 0 ]; then | |
| 47 | + | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w] $git_branch$git_dirty\n$ ' | |
| 48 | + | else | |
| 49 | + | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w]\n# ' | |
| 50 | + | fi | |
| 51 | + | fi | |
| 52 | + | unset color_prompt force_color_prompt | |
| 53 | + | ||
| 54 | + | # not sure what this bit does | |
| 55 | + | #case "$TERM" in | |
| 56 | + | # xterm*|rxvt*) | |
| 57 | + | # PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1";; | |
| 58 | + | # *) | |
| 59 | + | # ;; | |
| 60 | + | #esac | |
| 61 | + | ||
| 62 | + | # enable color support of ls and also add handy aliases | |
| 63 | + | if [ -x /usr/bin/dircolors ]; then | |
| 64 | + | test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" | |
| 65 | + | alias ls='ls --color=auto' | |
| 66 | + | alias dir='dir --color=auto' | |
| 67 | + | alias vdir='vdir --color=auto' | |
| 68 | + | ||
| 69 | + | alias grep='grep --color=auto' | |
| 70 | + | alias fgrep='fgrep --color=auto' | |
| 71 | + | alias egrep='egrep --color=auto' | |
| 72 | + | fi | |
| 73 | + | ||
| 74 | + | alias nano='nano --nowrap --smooth -T 4' | |
| 75 | + | alias plz='sudo ' | |
| 76 | + | alias dammit='sudo !!' | |
| 77 | + | ||
| 78 | + | # stop yourself from breaking the server by accident | |
| 79 | + | alias mv='mv -i' | |
| 80 | + | alias cp='cp -i' | |
| 81 | + | alias ln='ln -i' | |
| 82 | + | alias rm='rm -I --preserve-root' | |
| 83 | + | alias chown='chown --preserve-root' | |
| 84 | + | alias chmod='chmod --preserve-root' | |
| 85 | + | alias chgrp='chgrp --preserve-root' | |
| 86 | + | ||
| 87 | + | function findinfiles() { find ./ -type f -print0 | xargs -0 grep -i "$1"; } | |
| 88 | + | function findinphpfiles() { find ./ -type f -name "*.php" -print0 | xargs -0 grep -i "$1"; } | |
| 89 | + | ||
| 90 | + | complete -W "$(echo $(grep '^ssh ' ~/.bash_history | sort -u | sed 's/^ssh //'))" ssh | |
| 91 | + | ||
| 92 | + | if [ "$(uname)" == "Darwin" ]; then | |
| 93 | + | # got pbcopy | |
| 94 | + | : | |
| 95 | + | elif grep -q Microsoft /proc/version; then | |
| 96 | + | # route error to /dev/null because thanks microsoft | |
| 97 | + | alias pbcopy='clip.exe > /dev/null 2>&1' | |
| 98 | + | else | |
| 99 | + | # install xclip through apt first | |
| 100 | + | alias pbcopy='xclip -selection clipboard' | |
| 101 | + | alias pbpaste='xclip -selection clipboard -o' | |
| 102 | + | fi | |
| 103 | + | ||
| 104 | + | # thanks @jamesdoc | |
| 105 | + | alias e-thumbsup="printf \"👍\" | pbcopy && echo \"👍 copied to the clipboard\"" | |
| 106 | + | alias e-pointup="printf \"👆\" | pbcopy && echo \"👆 copied to the clipboard\"" | |
| 107 | + | alias e-pointdown="printf \"👇\" | pbcopy && echo \"👇 copied to the clipboard\"" | |
| 108 | + | alias e-rocket="printf \"🚀\" | pbcopy && echo \"🚀 copied to the clipboard\"" | |
| 109 | + | alias e-tada="printf \"🎉\" | pbcopy && echo \"🎉 copied to the clipboard\"" | |
| 110 | + | alias e-lightning="printf \"⚡\" | pbcopy && echo \"⚡ copied to the clipboard\"" | |
| 111 | + | alias shruggie="printf \"¯\_(ツ)_/¯\" | pbcopy && echo \"¯\_(ツ)_/¯ copied to clipboard\"" | |
| 112 | + | ||
| 113 | + | # ref https://github.com/dannyfritz/commit-message-emoji | |
| 114 | + | alias gc-InitialCommit="printf \"🎉\" | pbcopy && pbpaste && echo \"\"" | |
| 115 | + | alias gc-VersionTag="printf \"🔖\" | pbcopy && pbpaste && echo \"\"" | |
| 116 | + | alias gc-NewFeature="printf \"✨\" | pbcopy && pbpaste && echo \"\"" | |
| 117 | + | alias gc-Bugfix="printf \"🐛\" | pbcopy && pbpaste && echo \"\"" | |
| 118 | + | alias gc-SecurityFix="printf \"🔒\" | pbcopy && pbpaste && echo \"\"" | |
| 119 | + | alias gc-Metadata="printf \"📇\" | pbcopy && pbpaste && echo \"\"" | |
| 120 | + | alias gc-Refactoring="printf \"♻️\" | pbcopy && pbpaste && echo \"\"" | |
| 121 | + | alias gc-Documentation="printf \"📚\" | pbcopy && pbpaste && echo \"\"" | |
| 122 | + | alias gc-Internationalization="printf \"🌐\" | pbcopy && pbpaste && echo \"\"" | |
| 123 | + | alias gc-Accessibility="printf \"♿\" | pbcopy && pbpaste && echo \"\"" | |
| 124 | + | alias gc-Performance="printf \"🐎\" | pbcopy && pbpaste && echo \"\"" | |
| 125 | + | alias gc-Cosmetic="printf \"🎨\" | pbcopy && pbpaste && echo \"\"" | |
| 126 | + | alias gc-Tooling="printf \"🔧\" | pbcopy && pbpaste && echo \"\"" | |
| 127 | + | alias gc-Tests="printf \"🚨\" | pbcopy && pbpaste && echo \"\"" | |
| 128 | + | alias gc-Deprecation="printf \"💩\" | pbcopy && pbpaste && echo \"\"" | |
| 129 | + | alias gc-Removal="printf \"🗑️\" | pbcopy && pbpaste && echo \"\"" | |
| 130 | + | alias gc-WorkInProgress="printf \"🚧\" | pbcopy && pbpaste && echo \"\"" | |
| 131 | + | alias gc-Deforestation="printf \"🌲\" | pbcopy && pbpaste && echo \"\"" | |
| 132 | + | ||
| 133 | + | if [ -x /usr/bin/termsaver ]; then | |
| 134 | + | alias tsm="termsaver matrix" | |
| 135 | + | fi | |
| 136 | + | ||
| 137 | + | if [ -x /usr/bin/cmatrix ]; then | |
| 138 | + | alias etm="cmatrix -a -b -s -C cyan" | |
| 139 | + | fi | |
| 140 | + | ||
| 141 | + | # this is needed to enter the passphrase when attempting to gpg-sign git commits | |
| 142 | + | #export GPG_TTY=$(tty) | |
| 143 | + | ||
| 144 | + | # if you're on WSL you may want to see information from MOTD such as pending updates | |
| 145 | + | #sudo run-parts /etc/update-motd.d/ | |
| 146 | + | ||
| 147 | + | # if you're on WSL and you want to mount network shares | |
| 148 | + | #sudo mount -a | |
| 149 | + | ||
| 150 | + | # if you want to hide commands from your bash history with space and don't include duplicates | |
| 151 | + | # you need this but it may already be set elsewhere | |
| 152 | + | #HISTCONTROL=ignoreboth | |
| 153 | + | ||
| 154 | + | # Debian doesn't have bash-completion by default so you need to apt install bash-completion and add the below | |
| 155 | + | #if [ -f /etc/bash_completion ]; then | |
| 156 | + | # . /etc/bash_completion | |
| 157 | + | #fi | |
| @@ -1,129 +1,62 @@ | |||
| 1 | - | git_branch= | |
| 2 | - | git_dirty= | |
| 3 | - | if [ -d ~/.bash/git-aware-prompt ]; then | |
| 4 | - | source ~/.bash/git-aware-prompt/prompt.sh | |
| 5 | - | fi | |
| 1 | + | . /etc/bash.bashrc | |
| 6 | 2 | ||
| 7 | - | # set variable identifying the chroot you work in (used in the prompt below) | |
| 8 | - | if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then | |
| 9 | - | debian_chroot=$(cat /etc/debian_chroot) | |
| 10 | - | fi | |
| 3 | + | # https://askubuntu.com/a/22043 | |
| 4 | + | alias sudo='sudo ' | |
| 11 | 5 | ||
| 12 | - | # set a fancy prompt (non-color, unless we know we "want" color) | |
| 13 | - | case "$TERM" in | |
| 14 | - | xterm-color) color_prompt=yes;; | |
| 15 | - | esac | |
| 6 | + | # lol | |
| 7 | + | alias nano='vim' | |
| 16 | 8 | ||
| 17 | - | # uncomment for a colored prompt, if the terminal has the capability; turned | |
| 18 | - | # off by default to not distract the user: the focus in a terminal window | |
| 19 | - | # should be on the output of commands, not on the prompt | |
| 20 | - | force_color_prompt=yes | |
| 21 | - | ||
| 22 | - | if [ -n "$force_color_prompt" ]; then | |
| 23 | - | if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then | |
| 24 | - | # We have color support; assume it's compliant with Ecma-48 | |
| 25 | - | # (ISO/IEC-6429). (Lack of such support is extremely rare, and such | |
| 26 | - | # a case would tend to support setf rather than setaf.) | |
| 27 | - | color_prompt=yes | |
| 9 | + | function git { | |
| 10 | + | if [[ "$1" == "clone" && "$@" != *"--help"* ]]; then | |
| 11 | + | shift 1 | |
| 12 | + | command git clone --config core.filemode=false "$@" | |
| 13 | + | elif [[ "$1" == "branch" && "$@" != *"--help"* ]]; then | |
| 14 | + | shift 1 | |
| 15 | + | command git checkout -b "$@" | |
| 28 | 16 | else | |
| 29 | - | color_prompt= | |
| 17 | + | command git "$@" | |
| 30 | 18 | fi | |
| 31 | - | fi | |
| 19 | + | } | |
| 32 | 20 | ||
| 33 | - | if [ "$color_prompt" = yes ]; then | |
| 34 | - | if [ "$EUID" -ne 0 ]; then | |
| 35 | - | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[32m[\w] \e[1;34m$git_branch\e[31m$git_dirty\e[0m\n$ ' | |
| 21 | + | function docker { | |
| 22 | + | if [[ "$1" == "stop-and-rm" ]]; then | |
| 23 | + | shift 1 | |
| 24 | + | command docker stop "$@" | |
| 25 | + | command docker rm "$@" | |
| 36 | 26 | else | |
| 37 | - | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[31m[\w]\e[0m\n# ' | |
| 27 | + | command docker "$@" | |
| 38 | 28 | fi | |
| 39 | - | else | |
| 40 | - | if [ "$EUID" -ne 0 ]; then | |
| 41 | - | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w] $git_branch$git_dirty\n$ ' | |
| 42 | - | else | |
| 43 | - | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w]\n# ' | |
| 29 | + | } | |
| 30 | + | ||
| 31 | + | # aliases let you put things after the command if you want | |
| 32 | + | # i.e. get familiar with the flags but type way fewer characters | |
| 33 | + | # e.g. dc build --no-cache -> rebuild the images without cache | |
| 34 | + | # e.g. dcu -d -> dc up and detach/background it | |
| 35 | + | # e.g. dce app bash -> dc exec bash in the service | |
| 36 | + | # e.g. dcd -v -> dc down and clear volumes too | |
| 37 | + | alias dc=docker-compose | |
| 38 | + | alias dcd="docker-compose down" | |
| 39 | + | alias dcu="docker-compose up" | |
| 40 | + | alias dce="docker-compose exec" | |
| 41 | + | ||
| 42 | + | # persisting the changes you've made to your container | |
| 43 | + | # is a terrible idea and yet here it is | |
| 44 | + | function dcc { | |
| 45 | + | if [ "$#" -ne "1" ]; then | |
| 46 | + | echo "Precisely one argument required" | |
| 47 | + | return 1 | |
| 44 | 48 | fi | |
| 45 | - | fi | |
| 46 | - | unset color_prompt force_color_prompt | |
| 47 | - | ||
| 48 | - | case "$TERM" in | |
| 49 | - | xterm*|rxvt*) | |
| 50 | - | PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1";; | |
| 51 | - | *) | |
| 52 | - | ;; | |
| 53 | - | esac | |
| 54 | - | ||
| 55 | - | # enable color support of ls and also add handy aliases | |
| 56 | - | if [ -x /usr/bin/dircolors ]; then | |
| 57 | - | test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" | |
| 58 | - | alias ls='ls --color=auto' | |
| 59 | - | alias dir='dir --color=auto' | |
| 60 | - | alias vdir='vdir --color=auto' | |
| 61 | - | ||
| 62 | - | alias grep='grep --color=auto' | |
| 63 | - | alias fgrep='fgrep --color=auto' | |
| 64 | - | alias egrep='egrep --color=auto' | |
| 65 | - | fi | |
| 66 | - | ||
| 67 | - | alias nano='nano --nowrap --smooth -T 4' | |
| 68 | - | alias plz='sudo' | |
| 69 | - | alias dammit='sudo !!' | |
| 70 | - | ||
| 71 | - | # stop yourself from breaking the server by accident | |
| 72 | - | alias mv='mv -i' | |
| 73 | - | alias cp='cp -i' | |
| 74 | - | alias ln='ln -i' | |
| 75 | - | alias rm='rm -I --preserve-root' | |
| 76 | - | alias chown='chown --preserve-root' | |
| 77 | - | alias chmod='chmod --preserve-root' | |
| 78 | - | alias chgrp='chgrp --preserve-root' | |
| 79 | - | ||
| 80 | - | function findinfiles() { find ./ -type f -print0 | xargs -0 grep -i "$1"; } | |
| 81 | - | function findinphpfiles() { find ./ -type f -name "*.php" -print0 | xargs -0 grep -i "$1"; } | |
| 82 | 49 | ||
| 83 | - | complete -W "$(echo $(grep '^ssh ' ~/.bash_history | sort -u | sed 's/^ssh //'))" ssh | |
| 50 | + | CONTAINER=$(dc images | grep "_$1 " | awk '{print $1;}') | |
| 51 | + | TAGNAME=$(dc images | grep "_app " | awk '{print $2;}') | |
| 52 | + | TAGVERSION=$(dc images | grep "_app " | awk '{print $3;}') | |
| 84 | 53 | ||
| 85 | - | if [ "$(uname)" == "Darwin" ]; then | |
| 86 | - | # got pbcopy | |
| 87 | - | : | |
| 88 | - | elif grep -q Microsoft /proc/version; then | |
| 89 | - | # route error to /dev/null because thanks microsoft | |
| 90 | - | alias pbcopy='clip.exe > /dev/null 2>&1' | |
| 91 | - | else | |
| 92 | - | # install xclip through apt first | |
| 93 | - | alias pbcopy='xclip -selection clipboard' | |
| 94 | - | fi | |
| 95 | - | ||
| 96 | - | # thanks @jamesdoc | |
| 97 | - | alias e-thumbsup="printf \"👍\" | pbcopy && echo \"👍 copied to the clipboard\"" | |
| 98 | - | alias e-pointup="printf \"👆\" | pbcopy && echo \"👆 copied to the clipboard\"" | |
| 99 | - | alias e-pointdown="printf \"👇\" | pbcopy && echo \"👇 copied to the clipboard\"" | |
| 100 | - | alias e-rocket="printf \"🚀\" | pbcopy && echo \"🚀 copied to the clipboard\"" | |
| 101 | - | alias e-tada="printf \"🎉\" | pbcopy && echo \"🎉 copied to the clipboard\"" | |
| 102 | - | alias e-lightning="printf \"⚡\" | pbcopy && echo \"⚡ copied to the clipboard\"" | |
| 103 | - | alias shruggie="printf \"¯\_(ツ)_/¯\" | pbcopy && echo \"¯\_(ツ)_/¯ copied to clipboard\"" | |
| 104 | - | ||
| 105 | - | if [ -x /usr/bin/termsaver ]; then | |
| 106 | - | alias tsm="termsaver matrix" | |
| 107 | - | fi | |
| 108 | - | ||
| 109 | - | if [ -x /usr/bin/cmatrix ]; then | |
| 110 | - | alias etm="cmatrix -a -b -s -C cyan" | |
| 111 | - | fi | |
| 112 | - | ||
| 113 | - | # this is needed to enter the passphrase when attempting to gpg-sign git commits | |
| 114 | - | #export GPG_TTY=$(tty) | |
| 115 | - | ||
| 116 | - | # if you're on WSL you may want to see information from MOTD such as pending updates | |
| 117 | - | #sudo run-parts /etc/update-motd.d/ | |
| 118 | - | ||
| 119 | - | # if you're on WSL and you want to mount network shares | |
| 120 | - | #sudo mount -a | |
| 121 | - | ||
| 122 | - | # if you want to hide commands from your bash history with space and don't include duplicates | |
| 123 | - | # you need this but it may already be set elsewhere | |
| 124 | - | #HISTCONTROL=ignoreboth | |
| 54 | + | if [ "$CONTAINER" = "" ] || [ "$TAGNAME" = "" ] || [ "$TAGVERSION" = "" ]; then | |
| 55 | + | echo "Unable to figure out what to do" | |
| 56 | + | return 1 | |
| 57 | + | fi | |
| 125 | 58 | ||
| 126 | - | # Debian doesn't have bash-completion by default so you need to apt install bash-completion and add the below | |
| 127 | - | #if [ -f /etc/bash_completion ]; then | |
| 128 | - | # . /etc/bash_completion | |
| 129 | - | #fi | |
| 59 | + | COMMAND="docker commit $CONTAINER $TAGNAME:$TAGVERSION" | |
| 60 | + | echo $COMMAND | |
| 61 | + | eval $COMMAND | |
| 62 | + | } | |
| @@ -0,0 +1,7 @@ | |||
| 1 | + | # if running bash | |
| 2 | + | if [ -n "$BASH_VERSION" ]; then | |
| 3 | + | # include .bashrc if it exists | |
| 4 | + | if [ -f "$HOME/.bashrc" ]; then | |
| 5 | + | . "$HOME/.bashrc" | |
| 6 | + | fi | |
| 7 | + | fi | |
Will Power revised this gist 7 years ago · 6542063
1 file changed, 1 insertion, 1 deletion
| @@ -110,7 +110,7 @@ if [ -x /usr/bin/cmatrix ]; then | |||
| 110 | 110 | alias etm="cmatrix -a -b -s -C cyan" | |
| 111 | 111 | fi | |
| 112 | 112 | ||
| 113 | - | # on WSL this is needed to enter the passphrase when attempting to gpg-sign git commits | |
| 113 | + | # this is needed to enter the passphrase when attempting to gpg-sign git commits | |
| 114 | 114 | #export GPG_TTY=$(tty) | |
| 115 | 115 | ||
| 116 | 116 | # if you're on WSL you may want to see information from MOTD such as pending updates | |
Will Power revised this gist 8 years ago · 30725d0
1 file changed, 6 insertions, 1 deletion
| @@ -121,4 +121,9 @@ fi | |||
| 121 | 121 | ||
| 122 | 122 | # if you want to hide commands from your bash history with space and don't include duplicates | |
| 123 | 123 | # you need this but it may already be set elsewhere | |
| 124 | - | #HISTCONTROL=ignoreboth | |
| 124 | + | #HISTCONTROL=ignoreboth | |
| 125 | + | ||
| 126 | + | # Debian doesn't have bash-completion by default so you need to apt install bash-completion and add the below | |
| 127 | + | #if [ -f /etc/bash_completion ]; then | |
| 128 | + | # . /etc/bash_completion | |
| 129 | + | #fi | |
Will Power revised this gist 8 years ago · 866c117
1 file changed, 8 insertions, 2 deletions
| @@ -1,3 +1,9 @@ | |||
| 1 | + | git_branch= | |
| 2 | + | git_dirty= | |
| 3 | + | if [ -d ~/.bash/git-aware-prompt ]; then | |
| 4 | + | source ~/.bash/git-aware-prompt/prompt.sh | |
| 5 | + | fi | |
| 6 | + | ||
| 1 | 7 | # set variable identifying the chroot you work in (used in the prompt below) | |
| 2 | 8 | if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then | |
| 3 | 9 | debian_chroot=$(cat /etc/debian_chroot) | |
| @@ -26,13 +32,13 @@ fi | |||
| 26 | 32 | ||
| 27 | 33 | if [ "$color_prompt" = yes ]; then | |
| 28 | 34 | if [ "$EUID" -ne 0 ]; then | |
| 29 | - | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[32m[\w]\e[0m\n$ ' | |
| 35 | + | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[32m[\w] \e[1;34m$git_branch\e[31m$git_dirty\e[0m\n$ ' | |
| 30 | 36 | else | |
| 31 | 37 | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[31m[\w]\e[0m\n# ' | |
| 32 | 38 | fi | |
| 33 | 39 | else | |
| 34 | 40 | if [ "$EUID" -ne 0 ]; then | |
| 35 | - | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w]\n$ ' | |
| 41 | + | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w] $git_branch$git_dirty\n$ ' | |
| 36 | 42 | else | |
| 37 | 43 | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w]\n# ' | |
| 38 | 44 | fi | |
Will Power revised this gist 8 years ago · 3a647b9
1 file changed, 4 insertions
| @@ -112,3 +112,7 @@ fi | |||
| 112 | 112 | ||
| 113 | 113 | # if you're on WSL and you want to mount network shares | |
| 114 | 114 | #sudo mount -a | |
| 115 | + | ||
| 116 | + | # if you want to hide commands from your bash history with space and don't include duplicates | |
| 117 | + | # you need this but it may already be set elsewhere | |
| 118 | + | #HISTCONTROL=ignoreboth | |
Will Power revised this gist 8 years ago · ce6bde7
1 file changed, 3 insertions
| @@ -104,6 +104,9 @@ if [ -x /usr/bin/cmatrix ]; then | |||
| 104 | 104 | alias etm="cmatrix -a -b -s -C cyan" | |
| 105 | 105 | fi | |
| 106 | 106 | ||
| 107 | + | # on WSL this is needed to enter the passphrase when attempting to gpg-sign git commits | |
| 108 | + | #export GPG_TTY=$(tty) | |
| 109 | + | ||
| 107 | 110 | # if you're on WSL you may want to see information from MOTD such as pending updates | |
| 108 | 111 | #sudo run-parts /etc/update-motd.d/ | |
| 109 | 112 | ||
Will Power revised this gist 8 years ago · 85a7e6c
1 file changed, 7 insertions
| @@ -100,5 +100,12 @@ if [ -x /usr/bin/termsaver ]; then | |||
| 100 | 100 | alias tsm="termsaver matrix" | |
| 101 | 101 | fi | |
| 102 | 102 | ||
| 103 | + | if [ -x /usr/bin/cmatrix ]; then | |
| 104 | + | alias etm="cmatrix -a -b -s -C cyan" | |
| 105 | + | fi | |
| 106 | + | ||
| 103 | 107 | # if you're on WSL you may want to see information from MOTD such as pending updates | |
| 104 | 108 | #sudo run-parts /etc/update-motd.d/ | |
| 109 | + | ||
| 110 | + | # if you're on WSL and you want to mount network shares | |
| 111 | + | #sudo mount -a | |