Skip to content

Instantly share code, notes, and snippets.

@CyberAstronaut101
Created August 9, 2019 20:42
Show Gist options
  • Save CyberAstronaut101/27f66ba8dae867619451786c66639c7f to your computer and use it in GitHub Desktop.
Save CyberAstronaut101/27f66ba8dae867619451786c66639c7f to your computer and use it in GitHub Desktop.
custom oh-my-zsh theme
source /home/masonel/.oh-my-zsh/scripts/kube-ps1.sh
LINE_DIVIDER_='$FG[237]${(l.COLUMNS..-.)}'
# Grab the current date (%D) and time (%T) wrapped in {}: {%D %T}
CURRENT_TIME_="%{$fg[white]%}{%{$fg[yellow]%}%D %T%{$fg[white]%}} %{$reset_color%}"
# Grab the current machine name
CURRENT_MACH_="%{$FG[154]%}%m%{$fg[white]%} %{$reset_color%}"
# Define Custom Color Variables
eval my_gray='$FG[237]'
eval my_orange='$FG[214]'
# From Adam to switch between aws accounts with iam, use iam what to reset
function iam() {
[ "$1" = "what" ] && echo ${AWS_PROFILE:-default} && return
[ -n "$1" ] && local fzq="-q $*"
AWS_PROFILE="$(awk '/^\[/ { gsub("[\\[\\]]", "") ; print }' ~/.aws/credentials | fzf -e $fzq)"
echo "AWS_PROFILE -> $AWS_PROFILE"
asp $AWS_PROFILE
}
# Auth with gcloud sdk via `gcloud init`
# Switch between GCP projects with fzf search and select
function gcpproj(){
[ -n "$1" ] && local fzq="-q $*"
GCP_CURR_PROJECT="$( gcloud projects list | awk '{ print $1 }' | fzf -e $fzq)"
echo "** Changing current GCP project from $(gcloud config get-value project) to [$GCP_CURR_PROJECT]"
$(gcloud config set project $GCP_CURR_PROJECT)
}
# Switch between k8s clusters within a project with fzf search and select
function gcpkube() {
[ -n "$1" ] && local fzq="-q $*"
GCP_KUBE_CLUSTER="$( gcloud container clusters list | awk '{ print $1 }' | fzf -e $fzq)"
echo "Authenticating with k8s cluter: [$GCP_KUBE_CLUSTER]"
$(gcloud container clusters get-credentials $GCP_KUBE_CLUSTER)
}
# Functions for fzf
# Open and search history with fzf
function fh() {
print -z $( ([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s --tac | sed -r 's/ *[0-9]*\*? *//' | sed -r 's/\\/\\\\/g')
}
# Find-in-file
function fif() {
if [ ! "$#" -gt 1 ]; then echo "Need a string to search for!"; return 1; fi
rg --files-with-matches --no-messages $1 | fzf --preview "highlight -O ansi -l {} 2> /dev/null | rg --colors 'match:bg:yellow' --ignore-case --pretty --context 10 $1 || rg --ignore-case --pretty --context 10 $1 {}"
}
# fe [FUZZY PATTERN] - Open the selected file with the default editor
# - Bypass fuzzy finder if there's only one match (--select-1)
# - Exit if there's no match (--exit-0)
fe() {
local files
IFS=$'\n' files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
[[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}"
}
# Modified version where you can press
# - CTRL-O to open with `open` command,
# - CTRL-E or Enter key to open with the $EDITOR
fo() {
local out file key
IFS=$'\n' out=("$(fzf-tmux --query="$1" --exit-0 --expect=ctrl-o,ctrl-e)")
key=$(head -1 <<< "$out")
file=$(head -2 <<< "$out" | tail -1)
if [ -n "$file" ]; then
[ "$key" = ctrl-o ] && open "$file" || ${EDITOR:-vim} "$file"
fi
}
function cdf() {
local file
local dir
file=$(fzf +m -q "$1") && dir=$(dirname "$file") && cd "$dir"
}
# right prompt
if type "virtualenv_prompt_info" > /dev/null
then
RPROMPT='$(virtualenv_prompt_info)$my_gray%n@%m%{$reset_color%}%'
else
RPROMPT='$my_gray%n@%m%{$reset_color%}%'
fi
# git settings for custom colors
ZSH_THEME_GIT_PROMPT_PREFIX="$FG[075]($FG[078]"
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_DIRTY="$my_orange*%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="$FG[075])%{$reset_color%}"
PROMPT='
$my_orange${(l.COLUMNS..-.)} \
$CURRENT_TIME_\
$(kube_ps1)
$CURRENT_MACH_%{$fg_bold[green]%}%~%{$reset_color%}$(git_prompt_info) \
$FG[32]%(!.#.») %{$reset_color%}'
# $(git_prompt_info) \
# $CURRENT_MACH_$FG[32]%(!.#.»)%{$reset_color%}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment