{# symlink{~/.zshrc} #} # If you come from bash you might have to change your $PATH. # export PATH=$HOME/bin:/usr/local/bin:$PATH # Path to your oh-my-zsh installation. {%- if platform == "macos" %} export ZSH="$HOME/.oh-my-zsh" {%- else %} ZSH=/usr/share/oh-my-zsh/ {%- endif %} # Set name of the theme to load --- if set to "random", it will # load a random theme each time oh-my-zsh is loaded, in which case, # to know which specific one was loaded, run: echo $RANDOM_THEME # See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes ZSH_THEME="robbyrussell" # Configure a timer to be set just after the user hit enters on the command. # This hook fires after the command enter, but before it is actually executed. function preexec() { timer=${timer:-$SECONDS} } # Configure a post-run hook to display the duration if it took too long. # This cutoff can be configured using the if-statement. # This hooks fires after the command has been executed, before the prompt has been drawn. function precmd() { if [ $timer ]; then timer_show=$(($SECONDS - $timer)) timer_show=$(printf '%.*f\n' 0 $timer_show) if [ $timer_show -gt 2 ]; then seconds=$(($timer_show % 60)) minutes=$((($timer_show % 3600) / 60)) hours=$(($timer_show / 3600)) # print -P -- "$FG[007]Took ${timer_show} seconds%{$reset_color%}" string="$FG[007]Took" if [ $hours -gt 0 ]; then string+=" ${hours} hours" fi if [ $hours -gt 0 ] || [ $minutes -gt 0 ]; then string+=" ${minutes} minutes" fi string+=" ${seconds} seconds" string+="%{$reset_color%}" print -P -- $string fi unset timer fi } # Set list of themes to pick from when loading at random # Setting this variable when ZSH_THEME=random will cause zsh to load # a theme from this variable instead of looking in $ZSH/themes/ # If set to an empty array, this variable will have no effect. # ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" ) # Uncomment the following line to use case-sensitive completion. # CASE_SENSITIVE="true" # Uncomment the following line to use hyphen-insensitive completion. # Case-sensitive completion must be off. _ and - will be interchangeable. # HYPHEN_INSENSITIVE="true" {%- if platform == "macos" %} # Uncomment one of the following lines to change the auto-update behavior # zstyle ':omz:update' mode disabled # disable automatic updates # zstyle ':omz:update' mode auto # update automatically without asking zstyle ':omz:update' mode reminder # just remind me to update when it's time # Uncomment the following line to change how often to auto-update (in days). # zstyle ':omz:update' frequency 13 {%- else %} # Uncomment the following line to disable bi-weekly auto-update checks. DISABLE_AUTO_UPDATE="true" # Uncomment the following line to automatically update without prompting. # DISABLE_UPDATE_PROMPT="true" # Uncomment the following line to change how often to auto-update (in days). # export UPDATE_ZSH_DAYS=13 {%- endif %} # Uncomment the following line if pasting URLs and other text is messed up. # DISABLE_MAGIC_FUNCTIONS="true" # Uncomment the following line to disable colors in ls. # DISABLE_LS_COLORS="true" # Uncomment the following line to disable auto-setting terminal title. # DISABLE_AUTO_TITLE="true" # Uncomment the following line to enable command auto-correction. # ENABLE_CORRECTION="true" # Uncomment the following line to display red dots whilst waiting for completion. # Caution: this setting can cause issues with multiline prompts (zsh 5.7.1 and newer seem to work) # See https://github.com/ohmyzsh/ohmyzsh/issues/5765 # COMPLETION_WAITING_DOTS="true" # Uncomment the following line if you want to disable marking untracked files # under VCS as dirty. This makes repository status check for large repositories # much, much faster. # DISABLE_UNTRACKED_FILES_DIRTY="true" # Uncomment the following line if you want to change the command execution time # stamp shown in the history command output. # You can set one of the optional three formats: # "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" # or set a custom format using the strftime function format specifications, # see 'man strftime' for details. # HIST_STAMPS="mm/dd/yyyy" # Would you like to use another custom folder than $ZSH/custom? # ZSH_CUSTOM=/path/to/new-custom-folder # Which plugins would you like to load? # Standard plugins can be found in $ZSH/plugins/ # Custom plugins may be added to $ZSH_CUSTOM/plugins/ # Example format: plugins=(rails git textmate ruby lighthouse) # Add wisely, as too many plugins slow down shell startup. plugins=(git) # User configuration # export MANPATH="/usr/local/man:$MANPATH" # You may need to manually set your language environment # export LANG=en_US.UTF-8 # Preferred editor for local and remote sessions # if [[ -n $SSH_CONNECTION ]]; then # export EDITOR='vim' # else # export EDITOR='mvim' # fi # Compilation flags # export ARCHFLAGS="-arch x86_64" # Set personal aliases, overriding those provided by oh-my-zsh libs, # plugins, and themes. Aliases can be placed here, though oh-my-zsh # users are encouraged to define aliases within the ZSH_CUSTOM folder. # For a full list of active aliases, run `alias`. # # Example aliases # alias zshconfig="mate ~/.zshrc" # alias ohmyzsh="mate ~/.oh-my-zsh" ZSH_CACHE_DIR=$HOME/.cache/oh-my-zsh if [[ ! -d $ZSH_CACHE_DIR ]]; then mkdir $ZSH_CACHE_DIR fi source $ZSH/oh-my-zsh.sh function see() { [ -f "$*" ] && cat "$*" || ls "$*" } function docker-env() {( set -e run_command_switches=() workdir="/work_dir" function parse_port() { echo -n "$@" | perl -e ' my $line = <>; my ($defaultIp, $ip, $hostPort, $contPort) = $line =~ /^(?:([\d.]+) )?(?:(?:([\d.]+):)?(\d+):)?(\d+)$/; if (!$contPort) { print(STDERR "Invalid port format: \"$line\"\n"); exit(1); } if ($ip) { print "$ip:"; } else { if ($defaultIp) { print "$defaultIp:"; } } if ($hostPort) { print "$hostPort:"; } else { print "$contPort:"; } print "$contPort"; ' } while do case "$1" in --) shift break ;; -[evhmu]) run_command_switches+=("$1") run_command_switches+=("$2") shift ;; -p) run_command_switches+=("-p") run_command_switches+=("$(parse_port "127.0.0.1 $2")") shift ;; -P) run_command_switches+=("-p") run_command_switches+=("$(parse_port "$2")") shift ;; -E) [ -e "$2" ] || (echo "No such file or directory: $2">&2; exit 1) for arg in $(grep -v '^#' "$2" | xargs) do run_command_switches+=("-e") run_command_switches+=("$arg") done shift ;; -U) shift ;; -w) workdir="$2" shift ;; -r) shift ;; *) break ;; esac if [ $# -eq 0 ] then break fi shift done if [ $# -eq 0 ] then cat >&2 < Publish a container's port(s) to the host locally accessible (127.0.0.1) -P Publish a container's port(s) to the host publically accessible -e VAR=value Add environment variable VAR with value -E Load environment variables from a file -v Bind mount a volume -w Set working directory (default=/work_dir) -h Container hostname -m limit Memory limit -u user Username or UID (format: ]) -U user Same as -u, but create user if it does not exist (WIP) -r Raw argument to pass to \`docker run\` (WIP) EOS return 1 fi image="$1" shift cmd="$@" image_repository=$(echo -n "$image"| grep -Eo '^[^:]+' | tr '/' '-') index=$(docker ps -a --filter "name=docker-env-$image_repository-*" --format '{% raw %}{{.Names}}{% endraw %}' | perl -e 'my $max = 0; while (<>) {my ($n) = $_ =~ /(\d+)$/; if ($n > $max) { $max = $n };}; print $max+1;') name="docker-env-$image_repository-$index" run_command="docker run --rm -it --name \"$name\" -v \"$(pwd):/work_dir\" " for run_command_switch in $run_command_switches do run_command+="\"$run_command_switch\" " done run_command+="-w \"$workdir\" \"$image\" $cmd" eval $run_command )} # Completion for docker-env compdef _docker-env docker-env function _docker-env() { local curcontext="$curcontext" state _arguments \ "*-p[Publish a container's port(s) to the host locally accessible (127.0.0.1)]:port:" \ "*-P[Publish a container's port(s) to the host publically accessible]:port:" \ "*-e[Add environment variable VAR with value]:" \ "*-E[Load environment variables from a file]:file:_files" \ "*-v[Bind mount a volume]:" \ "-w[Working directory inside the container]" \ "-h[Container host name]" \ "-m[Memory limit]" \ "-u[Username or UID (format: (|(:)))]" \ "(-p -P -e -E -v -w -h -m -u)--[Explicitely stop switches and start positional arguments]" \ "(-p -P -e -E -v -w -h -m -u --)1:Container image:->image" \ "*:Container CMD:->cmd" case $state in image) # Check if you can find a colon, # if so strip everything up to that colon from further completion matching if compset -P -1 '*:'; then # Get the tags for the current image and use those for completion local tags=($(docker image ls --filter 'dangling=false' --filter 'reference='"${words[-1]}"'*' --format '{% raw %}{{.Tag}}{% endraw %}' | sed 's/:/\\:/g' | uniq)) # Add tags for autocompletion. If none exist, then show latest if [ {% raw %}${#tags}{% endraw %} -gt 0 ]; then compadd $tags else compadd "latest" fi else local repositories=($(docker image ls --filter 'dangling=false' --format "{% raw %}{{.Repository}}{% endraw %}" | sed 's/:/\\:/g' | uniq)) compadd -S : $repositories fi ;; cmd) _command_names ;; esac } function limit_video_size() { if [ $# -ne 3 ]; then echo "Usage: limit_video_size " return 1 else ffmpeg -i "$1" -fs $3M $2 fi } function setup_watcher() { if [ $# -lt 2 ]; then echo "Usage: $0 " return 1 else while inotifywait -e modify "$1"; do clear; eval "${@:2}"; done fi } function fuck { sudo ${history[@][1]} } {%- if platform == "linux" %} export SUDO_ASKPASS=~/bin/askpass-rofi {%- endif %} export EDITOR="nvim" {%- if platform == "macos" %} alias vim="nvim" export PATH="/usr/local/bin:$PATH" {%- endif %} export PATH="$PATH:/home/daniel/.yarn/bin" {%- if platform == "linux" %} export LC_ALL="en_US.UTF-8" {%- endif %} autoload -U +X bashcompinit && bashcompinit {%- if platform == "linux" %} complete -o nospace -C /usr/bin/terraform terraform {%- elif platform == "macos" %} complete -o nospace -C /usr/local/bin/terraform terraform {%- endif %} {%- if device == "macbook" %} # The next line updates PATH for the Google Cloud SDK. if [ -f '/Users/daniel.de.cloet/google-cloud-sdk/path.zsh.inc' ]; then . '/Users/daniel.de.cloet/google-cloud-sdk/path.zsh.inc'; fi # The next line enables shell command completion for gcloud. if [ -f '/Users/daniel.de.cloet/google-cloud-sdk/completion.zsh.inc' ]; then . '/Users/daniel.de.cloet/google-cloud-sdk/completion.zsh.inc'; fi {%- endif %} {%- if motd is defined %} {{ motd }} {%- else %} fortune -s {%- endif %}