Dotfiles_Generator/templates/zshrc

229 lines
7.5 KiB
Bash

{# 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() {
if [ $# -lt 1 ]; then
echo "Usage: docker-env <image_name> [command]"
return 1
else
name=$(echo -n $1| grep -Eo '^[^:]+')
index=$(docker ps -a --filter "name=docker-env-$name-*" --format '{% raw %}{{.Names}}{% endraw %}' | perl -e 'my $max = 0; while (<>) {my ($n) = $_ =~ /(\d+)$/; if ($n > $max) { $max = $n };}; print $max+1;')
docker run --rm --name "docker-env-$name-$index" -it -v "$(pwd):/work_dir" -w "/work_dir" "$1" "${2:-bash}"
fi
}
function limit_video_size() {
if [ $# -ne 3 ]; then
echo "Usage: limit_video_size <input_file> <output_file> <max_size (MB)>"
return 1
else
ffmpeg -i "$1" -fs $3M $2
fi
}
function setup_watcher() {
if [ $# -lt 2 ]; then
echo "Usage: $0 <file_to_watch> <command_to_exec>"
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" %}
export PATH="/usr/local/bin:$PATH"
{% endif %}
export PATH="$PATH:/home/daniel/.yarn/bin"
{% if device == "laptop" or device == "desktop" %}
export KUBECONFIG=~/.kube/k3s-mcintyre.yaml
{% endif %}
{% 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 %}
fortune -s