diff --git a/.gitignore b/.gitignore index ec24a19bb..45de4f1e7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ cache/ log/ *.swp .DS_Store +.history/* diff --git a/.tmux.conf b/.tmux.conf index 7a9a0bbf1..cd3ad9a22 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -45,6 +45,9 @@ set -g renumber-windows on # soften status bar color from harsh green to light gray set -g status-style bg='#262626',fg='#a1cfd1' +# set status bg to grey from https://protechnotes.com/comprehensive-tmux-tutorial-for-beginners-with-a-cheat-sheet/ +set -g status-bg colour236 + # remove administrative debris (session name, hostname, time) in status bar #set -g status-left '' #set -g status-right '' @@ -178,14 +181,13 @@ set -g @plugin 'tmux-plugins/tmux-open' set -g status-position bottom set -g status-justify left # Status line right side - 31-Oct 13:37 -set -g status-right "#[fg=cyan]%d %b %R" -set -g status-right-length 50 +#set -g status-right "#[fg=cyan]%d %b %R" setw -g window-status-current-style 'fg=colour1 bg=colour19 bold' setw -g window-status-current-format ' #I#[fg=colour249]:#[fg=colour255]#W#[fg=colour249]#F ' -setw -g window-status-style 'fg=colour9 bg=colour18' -setw -g window-status-format ' #I#[fg=colour237]:#[fg=colour250]#W#[fg=colour244]#F ' +#setw -g window-status-style 'fg=colour9 bg=colour18' +#setw -g window-status-format ' #I#[fg=colour237]:#[fg=colour250]#W#[fg=colour244]#F ' # setw -g window-status-bell-style 'fg=colour255 bg=colour1 bold' @@ -197,7 +199,11 @@ set -g status-left "#{prefix_highlight} #[fg=green]Session: #S #[fg=yellow]#I #[ set -g status-interval 5 # messages -# set -g message-style 'fg=colour232 bg=colour16 bold' +#set -g message-style 'fg=colour232 bg=colour16 bold' + +# https://github.com/jonmosco/kube-tmux.git +# set -g status-right-length 80 # long enough for our long cluster names +# set -g status-right "#(/bin/bash $HOME/.tmux/kube-tmux/kube.tmux 250 red cyan)" ########################## # PLUGINS @@ -205,6 +211,8 @@ set -g status-interval 5 # List of plugins set -g @plugin 'tmux-plugins/tpm' set -g @plugin 'tmux-plugins/tmux-sensible' +set -g @plugin 'jimeh/tmux-themepack' +set -g @themepack 'powerline/block/blue' # Other examples: # set -g @plugin 'github_username/plugin_name' diff --git a/.zsh_favlist b/.zsh_favlist new file mode 120000 index 000000000..d193016cf --- /dev/null +++ b/.zsh_favlist @@ -0,0 +1 @@ +/Users/peter/.zsh_favlist \ No newline at end of file diff --git a/kubernetes-util.sh b/kubernetes-util.sh new file mode 100644 index 000000000..81d9e1bce --- /dev/null +++ b/kubernetes-util.sh @@ -0,0 +1,116 @@ +alias ts-resolve-host="tsunami variables resolve --unit-type host " + +function ts-variables-show() { + tsunami variables show $1 $2 +} +function ts-variables-show-version() { + tsunami variables history $1 $2 +} + +alias tsunami-resolve-host="ts-resolve-host" +alias tsunami-variables-show="ts-variables-show" +alias tsunami-variables-show-version="ts-variables-show-version" + +# to avoid slow shells, we do it manually +function kubectl() { + if ! type __start_kubectl >/dev/null 2>&1; then + source <(command kubectl completion zsh) + fi + + command kubectl "$@" +} + +function kube-ctx-show() { + echo "`kubectl ctx -c` • `kubectl ns -c`" +} + +alias show-kube-ctx="kube-ctx-show" +alias kc-current-ctx="kube-ctx-show" + +function kube-list-local-contexts() { + grep '^- name: ' ~/.kube/config | awk '{print $3}' +} + +alias kc-list-local-contexts="kube-list-local-contexts" + +function kube-list-prod-contexts() { + gcloud container clusters list --project=gke-xpn-1 --filter="resourceLabels[env]=production" --format="value(name)" +} + +alias kc-list-prod-contexts="kube-list-prod-contexts" + +alias kc="kubectl" +alias k="kubectl" +alias mk="minikube" +alias kube-list-contexts="kubectl config get-contexts" + +alias kc-site="kubectl-site" + +# Record all pods belonging to a given namespace across all clusters that are +# configured +function list-all-pods-multi-cluster () { + mv all-pods.txt all-pods.txt~ 2>&1 > /dev/null + + KC_NS=$1 + echo + echo "Finding all pods for namespace $KC_NS across all configured clusters hello-k8s-replicaset.yaml# hello-k8s-replicaset.yaml +apiVersion: apps/v1 +kind: ReplicaSet +metadata: + name: hello-k8s- + namespace: tech-learning +spec: + replicas: 3 + selector: + matchLabels: + app: hello-k8s- + template: + metadata: + annotations: + podpreset.admission.spotify.com/exclude: 'ffwd-java-shim-container, spotify-envs' + labels: + app: hello-k8s- + spec: + containers: + - name: hello-k8s + image: gcr.io/tech-learning-2321/hello-k8s:0.0.1 + env: + - name: USER_OVERRIDE + value: "" + ports: + - name: http + containerPort: 8080 + resources: + requests: + cpu: 200m + memory: 1G + limits: + cpu: 800m + memory: 4Gand dumping them into ./all-pods.txt..." + echo + + for CLUSTER in `kubectl ctx`; do + case $CLUSTER in + kind ) + echo "Skipping ${CLUSTER}." + continue + ;; + docker ) + echo "Skipping ${CLUSTER}." + continue + ;; + minikube ) + echo "Skipping ${CLUSTER}." + continue + ;; + * ) + ;; + esac + + echo "Processing cluster $CLUSTER..." + + kubectl ctx $CLUSTER + kubectl ns $KC_NS + kubectl get pods -o wide >> all-pods.txt + done +} diff --git a/lib/functions.zsh b/lib/functions.zsh index c48bf71a9..07e5c6a6a 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -264,6 +264,11 @@ lsg() { l | grep -iE "$1" } +# These need to be here since they're required by gfind* +alias ag="/usr/local/homebrew/bin/ag --ignore '*.svg' --ignore '*.xlt' --ignore '*.tsx' --ignore '*.js' --ignore '*.snap' --ignore '*.json' --ignore '*.dat' --ignore '*.builds' --ignore '*.tsv' --ignore '*.csv' --ignore '*.lock' --ignore '*.patch' --ignore '*.sum' --pager=bat" +alias ag-no-pager="/usr/local/homebrew/bin/ag --ignore '*.svg' --ignore '*.xlt' --ignore '*.tsx' --ignore '*.js' --ignore '*.snap' --ignore '*.json' --ignore '*.dat' --ignore '*.builds' --ignore '*.tsv' --ignore '*.csv' --ignore '*.lock' --ignore '*.patch' --ignore '*.sum'" +alias "git-grep"="git \grep" + # the ol' gfind. Doesn't take a file pattern. function gfind-all() { # fd -H -t f . -x grep --color=always -Hi ${1} @@ -271,27 +276,18 @@ function gfind-all() { # $1 is search term, $2 is path # rg --no-ignore --hidden "$@" # even better is ag / silver searcher https://github.com/ggreer/the_silver_searcher - ag -a --pager less "$@" + ag-no-pager -a --pager bat "$@" } # the ol' gfind. Doesn't take a file pattern. function gfind() { # fd -t f . -x grep --color=always -Hi ${1} - ag --pager less "$@" + ag-no-pager --pager bat "$@" } # Print out the matches only function gfindf() { - # TODO make this a lot less shit e.g. don't search .git . Surely rg has - # the ability to do this. - find . -type f -exec grep --color=always -Hil $1 {} \; -} - -function heroic-repo-configure() { - cp ${HOME}/src/spotify/prism-tools/heroic-test.yml ./heroic-guc.yml - cp ${HOME}/src/spotify/prism-tools/heroic-api-gae.yml ./heroic-gae.yml - ls -l | grep -E 'heroic.*yml|heroic.*yaml' - mkdir logs + ack -l $1 --pager=bat --color } # function h() { @@ -351,6 +347,12 @@ function dir-sizes() { du -sh ./* | sort -h } +# Call from within the source TLD +function download-sources-intellij() { + mvn dependency:sources + mvn dependency:resolve -Dclassifier=javadoc +} + function ssh-ds718() { ssh -p 658 pskadmin@192.168.2.7 @@ -358,7 +360,7 @@ function ssh-ds718() { alias git-stash-list-all='gitk `git stash list --pretty=format:%gd`' -function master-show-protection() { +function git-show-protection() { git branch -vv | grep "origin/`git branch --show-current`" } @@ -373,11 +375,15 @@ function git-show-all-stashes() { } # kill most recent container instance -alias docker-kill-latest='docker ps -l --format='{{.Names}}' | xargs docker kill' +alias docker-kill-latest='docker ps -l --format="{{.Names}}" | xargs docker kill' # stop all containers -docker-stop-all-containers () { - docker container stop -t 2 $(docker container ls -q) 2>/dev/null +function docker-stop-all-containers () { + docker container stop -t 2 $(docker container ls -q) 2>/dev/null ; echo "" +} + +function docker-lsg () { + docker image ls | grep -Ei "'IMAGE ID'|$1" } function find-gig-files() { @@ -403,25 +409,63 @@ function start-cloud-storage() { ) & } +# Out of action - needs work +# function tree() { +# DIR=$1 ; +# shift # kubectl create -f hello-k8s-replicaset.yaml +# ps $1 off +# /usr/local/homebrew/bin/tree -a $DIR | colorize_less "$@" +# } -function tree() { - DIR=$1 ; - shift # pops $1 off - /usr/local/homebrew/bin/tree -a $DIR | colorize_less "$@" +function space() { + echo;echo;echo;echo;echo; +} + +alias s="space" + +function open-job-docs() { + open 'https://docs.google.com/document/d/1O81om1F14fNhWhqt5VpIULfiCHmNXPkFcMoED09cidU/edit' + open 'https://docs.google.com/document/d/1pBJfqcWhn9Wz6p6wPpPrk6_9MdGG_24qmpluz4pM3AY/edit' + open 'https://docs.google.com/document/d/1nj_MidYJEDhk1uzhPFOZ6uFdXfZY2hdrV0_f8zJ4Lgs/edit' + open 'https://docs.google.com/document/d/1gPNcLjrZJnJnWy0-k5SqpgP4VAUZ_ikRLR9qYEB50M0/edit' +} + +goclean() { + local pkg=$1; shift || return 1 + local ost + local cnt + local scr + + # Clean removes object files from package source directories (ignore error) + go clean -i $pkg &>/dev/null + + # Set local variables + [[ "$(uname -m)" == "x86_64" ]] \ + && ost="$(uname)";ost="${ost,,}_amd64" \ + && cnt="${pkg//[^\/]}" + + # Delete the source directory and compiled package directory(ies) + if (("${#cnt}" == "2")); then + rm -rf "${GOPATH%%:*}/src/${pkg%/*}" + rm -rf "${GOPATH%%:*}/pkg/${ost}/${pkg%/*}" + elif (("${#cnt}" > "2")); then + rm -rf "${GOPATH%%:*}/src/${pkg%/*/*}" + rm -rf "${GOPATH%%:*}/pkg/${ost}/${pkg%/*/*}" + fi } function _open-all-chrome-apps() { for APP in "${1}"/*.app; do echo "Opening $APP ..." - nohup open -a "$APP" & + nohup open -a "$APP" > /dev/null 2>&1 & done } function open-all-chrome-apps() { - CHROME_APP_DIR='/Users/peter/Dropbox (Personal)/_Settings/Chrome Apps/Chrome Apps.localized/' - _open-all-chrome-apps "$CHROME_APP_DIR" - CHROME_APP_DIR='/Users/peter/Dropbox (Personal)/_Settings/Chrome/Chrome Apps/Chrome Apps.localized/' - _open-all-chrome-apps "$CHROME_APP_DIR" + CHROME_APP_DIR='/Users/peter/Dropbox (Personal)/_Settings/Chrome Apps/Chrome Apps.localized' + _open-all-chrome-apps $CHROME_APP_DIR + CHROME_APP_DIR='/Users/peter/Dropbox (Personal)/_Settings/Chrome/Chrome Apps/Chrome Apps.localized' + _open-all-chrome-apps $CHROME_APP_DIR } function post-boot-tasks() { @@ -439,21 +483,18 @@ function kill-cloud-storage() { killall -v "FinderSyncExtension" -SIGKILL & } -# For photos, pictures, DS718 -function organise-into-dated-dirs() { - if [ $# -eq 0 ] - then - echo "Please supply an extension e.g. mov or mp4" - return - fi +function explain-command { + command="https://explainshell.com/explain?cmd=${1}" +osascript <