From 9a1cc66bd54af36192c6dc58d644101bf8dfe658 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 4 Feb 2019 03:32:45 +0100 Subject: [PATCH] Switched to Zgen Plugin manager --- .aliases | 6 - .zgenrc | 213 ++++++++++++++++++++++++++ .zsh_aliases | 27 ++++ .zshrc | 331 ++++++++++++++++++++++++++-------------- .zshrc.d/001-mkcd | 4 + .zshrc.d/002-newf | 9 ++ .zshrc.d/003-zurl | 25 +++ .zshrc.d/004-aliasing-k | 2 + 8 files changed, 495 insertions(+), 122 deletions(-) delete mode 100644 .aliases create mode 100644 .zgenrc create mode 100644 .zsh_aliases create mode 100644 .zshrc.d/001-mkcd create mode 100644 .zshrc.d/002-newf create mode 100644 .zshrc.d/003-zurl create mode 100644 .zshrc.d/004-aliasing-k diff --git a/.aliases b/.aliases deleted file mode 100644 index cfe6857..0000000 --- a/.aliases +++ /dev/null @@ -1,6 +0,0 @@ -alias ls='ls --color=auto' -alias dotfiles='/usr/bin/git --git-dir=/home/marty/.dotfiles/ --work-tree=/home/marty' -alias n='nnn' -alias m='micro' - -alias zshconf='m ~/.zshrc' diff --git a/.zgenrc b/.zgenrc new file mode 100644 index 0000000..0744ef6 --- /dev/null +++ b/.zgenrc @@ -0,0 +1,213 @@ +# Clone zgen if you haven't already +if [[ -z "$ZGEN_PARENT_DIR" ]]; then + ZGEN_PARENT_DIR=$HOME +fi +if [[ ! -f $ZGEN_PARENT_DIR/.zgen/zgen.zsh ]]; then + if [[ ! -d "$ZGEN_PARENT_DIR" ]]; then + mkdir -p "$ZGEN_PARENT_DIR" + fi + pushd $ZGEN_PARENT_DIR + git clone git@github.com:tarjoilija/zgen.git ./.zgen + popd +fi +source $ZGEN_PARENT_DIR/.zgen/zgen.zsh +unset ZGEN_PARENT_DIR + + +load-starter-plugin-list() { + echo "Creating a zgen save" + ZGEN_LOADED=() + ZGEN_COMPLETIONS=() + + zgen oh-my-zsh + + # If you want to customize your plugin list, create a file named + # .zgen-local-plugins in your home directory. That file will be sourced + # during startup *instead* of running this load-starter-plugin-list function, + # so make sure to include everything from this function that you want to keep. + + # If zsh-syntax-highlighting is bundled after zsh-history-substring-search, + # they break, so get the order right. + zgen load zdharma/fast-syntax-highlighting + zgen load zsh-users/zsh-history-substring-search + + # Set keystrokes for substring searching + zmodload zsh/terminfo + bindkey "$terminfo[kcuu1]" history-substring-search-up + bindkey "$terminfo[kcud1]" history-substring-search-down + + # Tab complete rakefile targets. + zgen load unixorn/rake-completion.zshplugin + + # Automatically run zgen update and zgen selfupdate every 7 days. + zgen load unixorn/autoupdate-zgen + + # Add my collection of miscellaneous utility functions. + #zgen load unixorn/jpb.zshplugin + + # Colorize the things if you have grc installed. Well, some of the + # things, anyway. + zgen load unixorn/warhol.plugin.zsh + + # macOS helpers. This plugin is smart enough to detect when it isn't running + # on macOS and not load itself, so you can safely share the same plugin list + # across macOS and Linux/BSD. + #zgen load unixorn/tumult.plugin.zsh + + # Warn you when you run a command that you've set an alias for without + # using the alias. + zgen load djui/alias-tips + + # Add my collection of git helper scripts. + zgen load unixorn/git-extra-commands + + # Add my bitbucket git helpers plugin. + #zgen load unixorn/bitbucket-git-helpers.plugin.zsh + + # A collection of scripts that might be useful to sysadmins. + # zgen load skx/sysadmin-util + + # Adds aliases to open your current repo & branch on github. + zgen load peterhurford/git-it-on.zsh + + # Tom Limoncelli's tooling for storing private information (keys, etc) + # in a repository securely by encrypting them with gnupg. + zgen load StackExchange/blackbox + + # Load some oh-my-zsh plugins + zgen oh-my-zsh plugins/pip + zgen oh-my-zsh plugins/sudo + zgen oh-my-zsh plugins/aws + zgen oh-my-zsh plugins/chruby + zgen oh-my-zsh plugins/colored-man-pages + zgen oh-my-zsh plugins/git + zgen oh-my-zsh plugins/github + zgen oh-my-zsh plugins/python + zgen oh-my-zsh plugins/rsync + zgen oh-my-zsh plugins/screen + zgen oh-my-zsh plugins/vagrant + zgen oh-my-zsh plugins/autojump + + if [ $(uname -a | grep -ci Darwin) = 1 ]; then + # Load macOS-specific plugins + zgen oh-my-zsh plugins/brew + zgen oh-my-zsh plugins/osx + fi + + # A set of shell functions to make it easy to install small apps and + # utilities distributed with pip. + zgen load sharat87/pip-app + + zgen load chrissicool/zsh-256color + + # Load more completion files for zsh from the zsh-lovers github repo. + zgen load zsh-users/zsh-completions src + + # Docker completion + zgen load srijanshetty/docker-zsh + + # Load me last + GENCOMPL_FPATH=$HOME/.zsh/complete + + # Very cool plugin that generates zsh completion functions for commands + # if they have getopt-style help text. It doesn't generate them on the fly, + # you'll have to explicitly generate a completion, but it's still quite cool. + zgen load RobSis/zsh-completion-generator + + # Add Fish-like autosuggestions to your ZSH. + zgen load zsh-users/zsh-autosuggestions + + # k is a zsh script / plugin to make directory listings more readable, + # adding a bit of color and some git status information on files and + # directories. + zgen load supercrabtree/k + + # Bullet train prompt setup. + zgen load bhilburn/powerlevel9k powerlevel9k + + # when in a directory with vagrant/docker files can use start, stop, up, down + zgen load Cloudstek/zsh-plugin-appup + + # automatically add .env contents to environment vars, as long as you're in the folder + zgen load zpm-zsh/autoenv + + # radically enhanced cd command, all sorts of options + zgen load b4b4r07/enhancd + + zgen load lukechilds/zsh-nvm + + # Save it all to init script. + zgen save +} + +setup-zgen-repos() { + if [[ -f ~/.zgen-local-plugins ]]; then + source ~/.zgen-local-plugins + else + load-starter-plugin-list + fi +} + +# This comes from https://stackoverflow.com/questions/17878684/best-way-to-get-file-modified-time-in-seconds +# This works on both Linux with GNU fileutils and macOS with BSD stat. + +# Naturally BSD/macOS and Linux can't share the same options to stat. +if [[ $(uname | grep -ci -e Darwin -e BSD) = 1 ]]; then + + # macOS version. + get_file_modification_time() { + modified_time=$(stat -f %m "$1" 2> /dev/null) || modified_time=0 + echo "${modified_time}" + } + +elif [[ $(uname | grep -ci Linux) = 1 ]]; then + + # Linux version. + get_file_modification_time() { + modified_time=$(stat -c %Y "$1" 2> /dev/null) || modified_time=0 + echo "${modified_time}" + } +fi + +# check if there's an init.zsh file for zgen and generate one if not. +if ! zgen saved; then + setup-zgen-repos +fi + + +# Our installation instructions get the user to make a symlink +# from ~/.zgen-setup to wherever they checked out the zsh-quickstart-kit +# repository. +# +# Unfortunately, stat will return the modification time of the +# symlink instead of the target file, so construct a full path to hand off +# to stat so it returns the modification time of the actual .zgen-setup file. +if [[ -f ~/.zgen-setup ]]; then + REAL_ZGEN_SETUP=~/.zgen-setup +fi +if [[ -L ~/.zgen-setup ]]; then + REAL_ZGEN_SETUP="$(readlink ~/.zgen-setup)" +fi + +# If you don't want my standard starter set of plugins, create a file named +# .zgen-local-plugins and add your zgen load commands there. Don't forget to +# run `zgen save` at the end of your .zgen-local-plugins file. +# +# Warning: .zgen-local-plugins REPLACES the starter list setup, it doesn't +# add to it. +# +# Use readlink in case the user is symlinking from another repo checkout, so +# they can use a personal dotfiles repository cleanly. +if [[ -f ~/.zgen-local-plugins ]]; then + REAL_ZGEN_SETUP=~/.zgen-local-plugins +fi +if [[ -L ~/.zgen-local-plugins ]]; then + REAL_ZGEN_SETUP="${HOME}/$(readlink ~/.zgen-local-plugins)" +fi + +# If .zgen-setup is newer than init.zsh, regenerate init.zsh +if [ $(get_file_modification_time ${REAL_ZGEN_SETUP}) -gt $(get_file_modification_time ~/.zgen/init.zsh) ]; then + echo "$(basename ${REAL_ZGEN_SETUP}) updated; creating a new init.zsh from plugin list in ${REAL_ZGEN_SETUP}" + setup-zgen-repos +fi +unset REAL_ZGEN_SETUP diff --git a/.zsh_aliases b/.zsh_aliases new file mode 100644 index 0000000..49467bc --- /dev/null +++ b/.zsh_aliases @@ -0,0 +1,27 @@ +if [[ "$(uname -s)" == "Linux" ]]; then + # we're on linux + alias l-d="ls -lFad" + alias l="ls -lAhF" + alias ll="ls -lFa | TERM=vt100 less" + alias ls='ls --color=auto' +fi + +# enables git management through dotfiles command +alias dotfiles='/usr/bin/git --git-dir=/home/marty/.dotfiles/ --work-tree=/home/marty' + +alias n='nnn' +alias m='micro' + +alias zshconf='m ~/.zshrc' + + +alias historysummary="history | awk '{a[\$2]++} END{for(i in a){printf \"%5d\t%s\n\",a[i],i}}' | sort -rn | head" +alias myip="curl -s icanhazip.com" + +alias reattach="screen -r" +alias zh="fc -l -d -D" + +alias ..="cd .." +alias ...="cd ../.." +alias ~="cd $HOME" + diff --git a/.zshrc b/.zshrc index f7ad945..1a03b0e 100644 --- a/.zshrc +++ b/.zshrc @@ -1,123 +1,185 @@ -# If you come from bash you might have to change your $PATH. -# export PATH=$HOME/bin:/usr/local/bin:$PATH +# Correct spelling for commands +setopt correct -# Path to your oh-my-zsh installation. - export ZSH="/home/marty/.oh-my-zsh" +# turn off the infernal correctall for filenames +unsetopt correctall -# 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/robbyrussell/oh-my-zsh/wiki/Themes -ZSH_THEME="powerlevel9k/powerlevel9k" - -# 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 ~/.oh-my-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" - -# Uncomment the following line to disable bi-weekly auto-update checks. -# DISABLE_AUTO_UPDATE="true" - -# Uncomment the following line to change how often to auto-update (in days). -# export UPDATE_ZSH_DAYS=13 - -# 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. -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 ~/.oh-my-zsh/plugins/* -# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ -# Example format: plugins=(rails git textmate ruby lighthouse) -# Add wisely, as too many plugins slow down shell startup. -plugins=( - git - colored-man-pages - zsh-completions - zsh-autosuggestions - zsh-syntax-highlighting - fzf -) - -source $ZSH/oh-my-zsh.sh - -# 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" - -# ssh -# export SSH_KEY_PATH="~/.ssh/rsa_id" - -# 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" -source $HOME/.aliases - -PS1='[\u@\h \W]\$ ' -# >>> Added by cnchi installer -BROWSER=/usr/bin/chromium -EDITOR=/usr/bin/micro - -. ~/.ssh/.ssh-find-agent.sh -ssh-find-agent -a -if [ -z "$SSH_AUTH_SOCK" ] -then - eval $(ssh-agent) > /dev/null - ssh-add -l >/dev/null || alias ssh='ssh-add -l >/dev/null || ssh-add && unalias ssh; ssh' +# start zgen +if [ -f ~/.zgenrc ]; then + source ~/.zgenrc fi -export GOPATH="$HOME/Code/go" -export PATH="$PATH:$GOPATH/bin" +# set some history options +setopt append_history +setopt extended_history +setopt hist_expire_dups_first +setopt hist_ignore_all_dups +setopt hist_ignore_dups +setopt hist_ignore_space +setopt hist_reduce_blanks +setopt hist_save_no_dups +setopt hist_verify + +# Share your history across all your terminal windows +setopt share_history +#setopt noclobber + +# set some more options +setopt pushd_ignore_dups +#setopt pushd_silent + +# Keep a ton of history. +HISTSIZE=100000 +SAVEHIST=100000 +HISTFILE=~/.zsh_history +export HISTIGNORE="ls:cd:cd -:pwd:exit:date:* --help" + +# Long running processes should return time after they complete. Specified +# in seconds. +REPORTTIME=2 +TIMEFMT="%U user %S system %P cpu %*Es total" + +# How often to check for an update. If you want to override this, the +# easiest way is to add a script fragment in ~/.zshrc.d that unsets +# QUICKSTART_KIT_REFRESH_IN_DAYS. +QUICKSTART_KIT_REFRESH_IN_DAYS=7 + +# Expand aliases inline - see http://blog.patshead.com/2012/11/automatically-expaning-zsh-global-aliases---simplified.html +globalias() { + if [[ $LBUFFER =~ ' [A-Z0-9]+$' ]]; then + zle _expand_alias + zle expand-word + fi + zle self-insert +} + +zle -N globalias + +bindkey " " globalias +bindkey "^ " magic-space # control-space to bypass completion +bindkey -M isearch " " magic-space # normal space during searches + +# Stuff only tested on zsh, or explicitly zsh-specific +if [ -r ~/.zsh_aliases ]; then + source ~/.zsh_aliases +fi + +# deal with screen, if we're using it - courtesy MacOSXHints.com +# Login greeting ------------------ +if [ "$TERM" = "screen" -a ! "$SHOWED_SCREEN_MESSAGE" = "true" ]; then + detached_screens=$(screen -list | grep Detached) + if [ ! -z "$detached_screens" ]; then + echo "+---------------------------------------+" + echo "| Detached screens are available: |" + echo "$detached_screens" + echo "+---------------------------------------+" + fi +fi + +# Speed up autocomplete, force prefix mapping +zstyle ':completion:*' accept-exact '*(N)' +zstyle ':completion:*' use-cache on +zstyle ':completion:*' cache-path ~/.zsh/cache +zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)*==34=34}:${(s.:.)LS_COLORS}")'; + +# Load any custom zsh completions we've installed +if [ -d ~/.zsh-completions ]; then + for completion in ~/.zsh-completions/* + do + source "$completion" + done +fi + + +# Make it easy to append your own customizations that override the above by +# loading all files from the ~/.zshrc.d directory +mkdir -p ~/.zshrc.d +if [ -n "$(/bin/ls ~/.zshrc.d)" ]; then + for dotfile in ~/.zshrc.d/* + do + if [ -r "${dotfile}" ]; then + source "${dotfile}" + fi + done +fi + +# In case a plugin adds a redundant path entry, remove duplicate entries +# from PATH +# +# This snippet is from Mislav Marohnić 's +# dotfiles repo at https://github.com/mislav/dotfiles +dedupe_path() { + typeset -a paths result + paths=($path) + + while [[ ${#paths} -gt 0 ]]; do + p="${paths[1]}" + shift paths + [[ -z ${paths[(r)$p]} ]] && result+="$p" + done + + export PATH=${(j+:+)result} +} + +dedupe_path + +# Do selfupdate checking. We do this after processing ~/.zshrc.d to make the +# refresh check interval easier to customize. +# +# If they unset QUICKSTART_KIT_REFRESH_IN_DAYS in one of the fragments +# in ~/.zshrc.d, then we don't do any selfupdate checking at all. + +_load-lastupdate-from-file() { + local now=$(date +%s) + if [[ -f "${1}" ]]; then + local last_update=$(cat "${1}") + else + local last_update=0 + fi + local interval="$(expr ${now} - ${last_update})" + echo "${interval}" +} + +_update-zsh-quickstart() { + if [[ ! -L ~/.zshrc ]]; then + echo ".zshrc is not a symlink, skipping zsh-quickstart-kit update" + else + local _link_loc=$(readlink ~/.zshrc); + if [[ "${_link_loc/${HOME}}" == "${_link_loc}" ]] then + pushd $(dirname "${HOME}/$(readlink ~/.zshrc)"); + else + pushd $(dirname ${_link_loc}); + fi; + local gitroot=$(git rev-parse --show-toplevel) + if [[ -f "${gitroot}/.gitignore" ]]; then + if [[ $(grep -c zsh-quickstart-kit "${gitroot}/.gitignore") -ne 0 ]]; then + echo "---- updating ----" + git pull + date +%s >! ~/.zsh-quickstart-last-update + fi + else + echo 'No quickstart marker found, is your quickstart a valid git checkout?' + fi + popd + fi +} + +_check-for-zsh-quickstart-update() { + local day_seconds=$(expr 24 \* 60 \* 60) + local refresh_seconds=$(expr "${day_seconds}" \* "${QUICKSTART_KIT_REFRESH_IN_DAYS}") + local last_quickstart_update=$(_load-lastupdate-from-file ~/.zsh-quickstart-last-update) + + if [ ${last_quickstart_update} -gt ${refresh_seconds} ]; then + echo "It has been $(expr ${last_quickstart_update} / ${day_seconds}) days since your zsh quickstart kit was updated" + echo "Checking for zsh-quickstart-kit updates..." + _update-zsh-quickstart + fi +} +# +# if [[ ! -z "$QUICKSTART_KIT_REFRESH_IN_DAYS" ]]; then +# _check-for-zsh-quickstart-update +# unset QUICKSTART_KIT_REFRESH_IN_DAYS +# fi POWERLEVEL9K_MODE='nerdfont-complete' #POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 @@ -159,3 +221,40 @@ POWERLEVEL9K_BACKGROUND_JOBS_BACKGROUND='clear' POWERLEVEL9K_BACKGROUND_JOBS_FOREGROUND='green' ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=250" + +# Uncomment the following line to enable command auto-correction. +ENABLE_CORRECTION="true" + +# Uncomment the following line to display red dots whilst waiting for completion. +COMPLETION_WAITING_DOTS="true" + +# You may need to manually set your language environment +#export LANG=en_US.UTF-8 + + + +# 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" +source $HOME/.zsh_aliases + +#PS1='[\u@\h \W]\$ ' +# >>> Added by cnchi installer +BROWSER=/usr/bin/chromium +EDITOR=/usr/bin/micro + +. ~/.ssh/.ssh-find-agent.sh +ssh-find-agent -a +if [ -z "$SSH_AUTH_SOCK" ] +then + eval $(ssh-agent) > /dev/null + ssh-add -l >/dev/null || alias ssh='ssh-add -l >/dev/null || ssh-add && unalias ssh; ssh' +fi + +export GOPATH="$HOME/Code/go" +export PATH="$PATH:$GOPATH/bin" diff --git a/.zshrc.d/001-mkcd b/.zshrc.d/001-mkcd new file mode 100644 index 0000000..f1e39fd --- /dev/null +++ b/.zshrc.d/001-mkcd @@ -0,0 +1,4 @@ +# mkdir & cd +function mkcd { + mkdir -p "$@" && cd $_ +} diff --git a/.zshrc.d/002-newf b/.zshrc.d/002-newf new file mode 100644 index 0000000..79d609c --- /dev/null +++ b/.zshrc.d/002-newf @@ -0,0 +1,9 @@ +# show newest files +# http://www.commandlinefu.com/commands/view/9015/find-the-most-recently-changed-files-recursively +newest (){ + find . -type f -printf '%TY-%Tm-%Td %TT %p\n' | \ + grep -v cache | \ + grep -v '.hg' | grep -v '.git' | \ + sort -r | \ + less +} diff --git a/.zshrc.d/003-zurl b/.zshrc.d/003-zurl new file mode 100644 index 0000000..d3e34fb --- /dev/null +++ b/.zshrc.d/003-zurl @@ -0,0 +1,25 @@ +# Create short urls via http://goo.gl using curl(1). +# Contributed back to grml zshrc +# API reference: https://code.google.com/apis/urlshortener/ +function zurl { + if [[ -z $1 ]]; then + print "USAGE: $0 " + return 1 + fi + + local url=$1 + local api='https://www.googleapis.com/urlshortener/v1/url' + local data + + # Prepend "http://" to given URL where necessary for later output. + if [[ $url != http(s|)://* ]]; then + url="http://$url" + fi + local json="{\"longUrl\": \"$url\"}" + + data=$(curl --silent -H "Content-Type: application/json" -d $json $api) + # Match against a regex and print it + if [[ $data =~ '"id": "(http://goo.gl/[[:alnum:]]+)"' ]]; then + print $match + fi +} diff --git a/.zshrc.d/004-aliasing-k b/.zshrc.d/004-aliasing-k new file mode 100644 index 0000000..73cc2b2 --- /dev/null +++ b/.zshrc.d/004-aliasing-k @@ -0,0 +1,2 @@ +alias k="k -h" +alias l="k -h"