From a53788f5c4fe271bb3d26e59ce3e5768d725d9bc Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Fri, 20 Jul 2018 00:46:33 +0100 Subject: [PATCH] Major revamp of shell init - drop bash support, focus on zsh --- .gitignore | 6 +- .gitmodules | 11 +- Makefile | 17 +- install.sh | 2 +- load_shellrc.sh | 2 +- shell/_main.sh | 51 --- shell/bash/bash-ido.sh | 374 ------------------ shell/bash/git-aware-prompt | 1 - shell/bash/prompt.sh | 14 - shell/bashrc.sh | 14 - shell/env.sh | 23 -- shell/helpers.sh | 8 - shell/osx.sh | 39 -- shell/svn.sh | 3 - shell/tmpdir.sh | 9 - shell/zsh/zplug-cache/.gitignore | 2 - shell/zsh/zplug-cache/repos/.gitkeep | 0 shell/zshrc.zsh | 65 --- shellrc.sh | 24 -- {shell/tmux => tmux}/tmuxifier | 0 shell/aliases.sh => zsh/aliases.zsh | 0 shell/docker.sh => zsh/docker.zsh | 0 shell/emacs.sh => zsh/emacs.zsh | 0 shell/git.sh => zsh/git.zsh | 0 shell/golang.sh => zsh/golang.zsh | 0 shell/google-cloud.sh => zsh/google-cloud.zsh | 0 shell/kubernetes.sh => zsh/kubernetes.zsh | 0 shell/less.sh => zsh/less.zsh | 0 zsh/linux.zsh | 8 + shell/nodejs.sh => zsh/nodejs.zsh | 0 zsh/osx.zsh | 41 ++ .../path_helpers.sh => zsh/path_helpers.zsh | 0 shell/ruby.sh => zsh/ruby.zsh | 0 shell/rust.sh => zsh/rust.zsh | 0 shell/tmux.sh => zsh/tmux.zsh | 11 +- .../zsh/plugins => zsh/zplug/cache}/.gitkeep | 0 .../cache => zsh/zplug/repos}/.gitkeep | 0 {shell/zsh => zsh/zplug}/zplug | 0 zshrc.zsh | 134 +++++++ 39 files changed, 210 insertions(+), 649 deletions(-) delete mode 100755 shell/_main.sh delete mode 100644 shell/bash/bash-ido.sh delete mode 160000 shell/bash/git-aware-prompt delete mode 100644 shell/bash/prompt.sh delete mode 100644 shell/bashrc.sh delete mode 100644 shell/env.sh delete mode 100644 shell/helpers.sh delete mode 100644 shell/osx.sh delete mode 100644 shell/svn.sh delete mode 100644 shell/tmpdir.sh delete mode 100644 shell/zsh/zplug-cache/.gitignore delete mode 100644 shell/zsh/zplug-cache/repos/.gitkeep delete mode 100644 shell/zshrc.zsh delete mode 100644 shellrc.sh rename {shell/tmux => tmux}/tmuxifier (100%) rename shell/aliases.sh => zsh/aliases.zsh (100%) rename shell/docker.sh => zsh/docker.zsh (100%) rename shell/emacs.sh => zsh/emacs.zsh (100%) rename shell/git.sh => zsh/git.zsh (100%) rename shell/golang.sh => zsh/golang.zsh (100%) rename shell/google-cloud.sh => zsh/google-cloud.zsh (100%) rename shell/kubernetes.sh => zsh/kubernetes.zsh (100%) rename shell/less.sh => zsh/less.zsh (100%) create mode 100644 zsh/linux.zsh rename shell/nodejs.sh => zsh/nodejs.zsh (100%) create mode 100644 zsh/osx.zsh rename shell/helpers/path_helpers.sh => zsh/path_helpers.zsh (100%) rename shell/ruby.sh => zsh/ruby.zsh (100%) rename shell/rust.sh => zsh/rust.zsh (100%) rename shell/tmux.sh => zsh/tmux.zsh (72%) rename {shell/zsh/plugins => zsh/zplug/cache}/.gitkeep (100%) rename {shell/zsh/zplug-cache/cache => zsh/zplug/repos}/.gitkeep (100%) rename {shell/zsh => zsh/zplug}/zplug (100%) create mode 100644 zshrc.zsh diff --git a/.gitignore b/.gitignore index a8caf10..dffd67c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,12 @@ .AppleDouble -Icon* +.SyncArchive/* .SyncID .SyncIgnore -.SyncArchive/* .dropbox +Icon* bin/boot2docker.iso bundle/cache/* private/* tmux/plugins/* +zsh/zplug/cache/* +zsh/zplug/repos/* diff --git a/.gitmodules b/.gitmodules index 3388b90..51eab98 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,15 +4,12 @@ [submodule "private"] path = private url = git@bitbucket.org:jimeh/dotfiles-private.git -[submodule "shell/tmux/tmuxifier"] - path = shell/tmux/tmuxifier +[submodule "tmux/tmuxifier"] + path = tmux/tmuxifier url = git@github.com:jimeh/tmuxifier.git -[submodule "shell/bash/git-aware-prompt"] - path = shell/bash/git-aware-prompt - url = git@github.com:jimeh/git-aware-prompt.git [submodule "tmux/plugins/tpm"] path = tmux/plugins/tpm url = https://github.com/tmux-plugins/tpm -[submodule "shell/zsh/zplug"] - path = shell/zsh/zplug +[submodule "zsh/zplug/zplug"] + path = zsh/zplug/zplug url = https://github.com/zplug/zplug diff --git a/Makefile b/Makefile index 5e0ad97..3125eff 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,13 @@ -.PHONY: backup-zplug-cache -backup-zplug-cache: - cd shell/zsh \ - && tar -cjf zplug-cache-$(shell date "+%Y-%m-%d").tar.bz2 zplug-cache +.PHONY: backup-zplug +backup-zplug: \ + zsh/zplug-$(shell date "+%Y-%m-%d").tar.bz2 .PHONY: backup-tmux-plugins -backup-tmux-plugins: - cd tmux && tar -cjf tmux-plugins-$(shell date "+%Y-%m-%d").tar.bz2 plugins +backup-tmux-plugins: \ + tmux/tmux-plugins-$(shell date "+%Y-%m-%d").tar.bz2 + +zsh/zplug-%.tar.bz2: zsh/zplug + cd zsh && tar -cjf "$(shell basename "$@")" zplug + +tmux/tmux-plugins-%.tar.bz2: tmux/plugins + cd tmux && tar -cjf "$(shell basename "$@")" plugins diff --git a/install.sh b/install.sh index 871655d..337dec5 100755 --- a/install.sh +++ b/install.sh @@ -32,7 +32,7 @@ SYMLINKS=( tmux tmux.conf ) -LOAD_FILES=(profile zshrc) +LOAD_FILES=(zshrc) # diff --git a/load_shellrc.sh b/load_shellrc.sh index 1abb828..11e8f70 100644 --- a/load_shellrc.sh +++ b/load_shellrc.sh @@ -1 +1 @@ -source "$HOME/.dotfiles/shellrc.sh" +source "$HOME/.dotfiles/zshrc.zsh" diff --git a/shell/_main.sh b/shell/_main.sh deleted file mode 100755 index 7dff539..0000000 --- a/shell/_main.sh +++ /dev/null @@ -1,51 +0,0 @@ -# -# Main Shell Setup -# - -# Ensure 256 color support in Linux -if [[ "$(uname)" == "Linux" ]]; then - export TERM="xterm-256color" -fi - -# Set required path variables -DOTBIN="$DOTFILES/bin" - -# Helper Functions -source "$DOTSHELL/helpers.sh" - -# Ensure /usr/local/bin is before various system-paths -path_prepend "/usr/local/bin" - -# Load bash or zsh specific init files -if [ -n "$BASH_VERSION" ]; then - source "$DOTSHELL/bashrc.sh" -elif [ -n "$ZSH_VERSION" ]; then - source "$DOTSHELL/zshrc.zsh" -fi - -# Aliases -source "$DOTSHELL/aliases.sh" - -# OSX specific -if [[ "$(uname)" == "Darwin" ]]; then - source "$DOTSHELL/osx.sh" -fi - -# Utils -source "$DOTSHELL/emacs.sh" -source "$DOTSHELL/git.sh" -source "$DOTSHELL/tmux.sh" -source "$DOTSHELL/less.sh" - -# Development -source "$DOTSHELL/nodejs.sh" -source "$DOTSHELL/ruby.sh" -source "$DOTSHELL/rust.sh" -source "$DOTSHELL/golang.sh" -source "$DOTSHELL/docker.sh" -source "$DOTSHELL/google-cloud.sh" -source "$DOTSHELL/kubernetes.sh" - -# Environment Setup -source "$DOTSHELL/env.sh" -source "$DOTSHELL/tmpdir.sh" diff --git a/shell/bash/bash-ido.sh b/shell/bash/bash-ido.sh deleted file mode 100644 index fe2d758..0000000 --- a/shell/bash/bash-ido.sh +++ /dev/null @@ -1,374 +0,0 @@ -## bash-ido - attempt to simulate a interactive menu similar to -# ido-mode in emacs -# -# URL: http://pgas.freeshell.org/shell/bash-ido - -# Author: -# Version: 1.0beta2 -# CVS: $Id: bash-ido,v 1.18 2010/02/13 14:50:32 pgas Exp $ - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with BASH-IDO; see the file COPYING. If not, write to the -# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -# Boston, MA 02110-1301, USA. -# - -# Documentation: -# -------------- - -# This is a fairly complex completion script for cd. (For now, i tried -# to make the functions a bit generic so that the menu can be used for -# other completions. Let me know if you need some help or something) -# It mimics what ido-mode does in emacs.This script also masks the -# normal cd with a function to track the list of the directory -# used. It's easier to try than to describe, here is a little getting -# started: -# -# 0) Source this script in your .bashrc (. /path/to/bash-ido) -# 1) Start your cd command, press TAB, type some letters the list of dirs is -# filtered according to these letters. -# 2) Press RET to select the first dir in the list. -# 3) DEL ie the erase key (usually backspace or ^H), to delete a search letter. -# When there are no more letters, pressing DEL let you go up one dir. -# 4) C-s or cycles the list to the right, C-r or to the left -# 5) C-g or C-c cancels the completion. -# 6) Typing 2 / will put you in /, typing /~/ will put you in $HOME -# 7) up/M-s and down/M-r allows to navigate in the history - -# Limitations -# ----------- -# * You cannot start completion after a dirname in " " or ' ' -# (actually it's probably possible if you modify COMP_WORDBREAKS) -# * It doesn't expand the ~user/ dirs, if you need this please tell me -# * The completion disables and re-enables C-c using stty, -# if you use another char for intr you need to modify -# the hard coded value (search for $'\003') this could be found via stty -# or a parameter could be defined but how well....tell me if you feel this -# is needed. -# * It probably doesn't work too well with huge dirs (a security check could -# perhaps be implemented). - -# Implementation Notes: -# --------------------- -# * Not sure what bash version is required. -# * It Probably doesn't work too well with some strange filenames. -# * All the functions and variables in this file should be prefixed by _ido_ -# to avoid namespace polution -# * Use stty rather than a trap to disable sigint....I couldn't do what -# I wanted with trap. -# * I choose to use the hardcoded ansi codes rather than tput, it should be -# a tad faster and reduce the dependencies, if you it doesn't work in your -# terminal please tell me. - -# TODO: -# ----- -# * add an example for other completions -# * support for CDPATH in dir completion? -# * implement persitent history? -# * complete on ~ first and handle ~user? - -# Global vars -# ----------- -# _ido_menu -- the list of choices -# _ido_f_menu -- the filtered menu -# _ido_search_string -- the characters typed so far -# _ido_result -- the dirname part of the search - _ido_history_size=100 # -- maximum dir entries in the history -# _ido_history -- list of the directories in the history -# _ido_history_point -- pointer to the current history entry - -# Functions -# --------- -# _ido_print_menu -- print the filtered menu -# _ido_loop -- the main keyboard event loop -# _ido_filter -- filters the menu -# _ido_gen_dir -- generate the original menu (list of dirs) -# _ido_dir -- entry point - -# Changes -# ------- -# 1.0b2 -# * fix ../ behaviour -# * fix TAB behaviour - -shopt -s checkwinsize #so that COLUMNS stays up to date - -_ido_print_f_menu () { - # Prints the directories limited on one line... - # We would need some terminal commands to clear more than one line - local prompt menu i cur - prompt=${_ido_result}${_ido_search_string} - if (( ${#_ido_f_menu[@]} ));then - menu="{ ${_ido_f_menu[0]#* }" - i=1 - while cur=${_ido_f_menu[i]#* }; - (( i < (${#_ido_f_menu[@]} -1) - && (${#menu}+${#prompt} +${#cur}+11) < COLUMNS )) \ - || (( i == (${#_ido_f_menu[@]} -1) - && (${#menu}+${#prompt}+${#cur}+4) < COLUMNS)); do - menu+=" | ${cur}" - i=$((i+1)) - done - if ((i < (${#_ido_f_menu[@]} -1) )) ; then - menu+=" | ... }" - else - menu+=" }" - fi - #yet another hack to put the cursor after the search string. - printf "\r%*s\r%*s%s\r%s" $COLUMNS " " ${#prompt} " " "$menu" "$prompt" - else - printf "\r%*s\r%*s%s\r%s" $COLUMNS " " ${#prompt} " " "[ No Match]" "$prompt" - fi -} - -_ido_filter () { - local i start trans_i cas quoted - if shopt -q nocasematch;then - cas=set - else - shopt -s nocasematch - fi - start=${_ido_f_menu[i]%% *} - unset _ido_f_menu - if [[ "$_ido_search_string" ]];then - printf -v quoted "%q" "$_ido_search_string" - else - quoted="" - fi - for i in "${!_ido_menu[@]}";do - trans_i=$(((i+start)%${#_ido_menu[@]})) - if [[ "${_ido_menu[trans_i]}" = *"$quoted"* ]];then - _ido_f_menu+=( "$trans_i ${_ido_menu[trans_i]}" ) - fi - done - if [[ -z $cas ]];then - shopt -u nocasematch - fi -} - -_ido_loop () { - local REPLY c - while :;do - _ido_print_f_menu >&2 - unset c - while :;do - #loop to read the escape sequences - IFS= read -d '' -r -s -n 1 - case $REPLY in - $'\E') - c+=$REPLY - ;; - \[|O) - c+=$REPLY - if ((${#c} ==1));then - break - fi - ;; - *) - c+=$REPLY - break - ;; - esac - done - case $c in - $'\n'|$'\t') # RET - _ido_result="${_ido_result}${_ido_f_menu[0]#* }" - return 0 - ;; - / ) # / - case $_ido_search_string in - ..) - _ido_result+="../" - ;; - \~) - _ido_result="$HOME/" - ;; - ?*) - _ido_result="${_ido_result}${_ido_f_menu[0]#* }" - ;; - *) - _ido_result=/ - ;; - esac - return 0 - ;; - '$\b'|$'\177') #DEL aka ^? or ^h - if [[ $_ido_search_string ]]; then - _ido_search_string=${_ido_search_string%?} - _ido_filter - else - _ido_result+="../" - return 0 - fi - ;; - $'\a' | $'\003') # C-g | C-c - return 2 - ;; - $'\E[C'|$'\EOC'|$'\023') # | C-s - if ((${#_ido_f_menu[@]}>1));then - _ido_f_menu=("${_ido_f_menu[@]:1}" "${_ido_f_menu[0]}") - fi - ;; - $'\E[D'|$'\EOD'|$'\022') # | C-r - if ((${#_ido_f_menu[@]}>1));then - _ido_f_menu=("${_ido_f_menu[${#_ido_f_menu[@]}-1]}" - "${_ido_f_menu[@]:0:${#_ido_f_menu[@]}-1}") - fi - ;; - $'\E[B'|$'\EOB'|$'\367'|$'\Er') # | M-r - if ((_ido_history_point>1));then - _ido_history_point=$((_ido_history_point-1)) - _ido_result=${_ido_history[_ido_history_point]%/}/ - _ido_search_string="" - return 0 - else - printf "\a" >&2 - fi - ;; - $'\E[A'|$'\EOA'|$'\362'|$'\Es') # | M-s - if (((_ido_history_point+1)< ${#_ido_history[@]}));then - _ido_history_point=$((_ido_history_point+1)) - _ido_result=${_ido_history[_ido_history_point]%/}/ - _ido_search_string="" - return 0 - else - printf "\a" >&2 - fi - ;; - [[:print:]]) - _ido_search_string+=$REPLY - _ido_filter - ;; - *) - printf "\a" >&2 -# printf "%q\n" "$c" - ;; - esac - done -} - -_ido_gen_dir () { - # return a list of subdir in _ido_result, - local pattern - case $_ido_search_string in - ..) - pattern=../ - ;; - .) - pattern="./ ..?*/ .[!.]*/ */" - ;; - .?*) - pattern="..?*/ .[!.]*/ */" - ;; - *) - pattern="./ */ ..?*/ .[!.]*/" - ;; - esac - _ido_result=${_ido_result/#~\//$HOME/} - unset _ido_menu - IFS=$'\n' read -r -d '' -a _ido_menu \ - < <(IFS=" ";shopt -s nullglob;\ - eval command cd "$_ido_result" 2>/dev/null \ - && printf -- "%q\n" $pattern) - if [[ $_ido_search_string ]];then - _ido_filter - else - local i e - unset _ido_f_menu - for e in "${_ido_menu[@]}";do - _ido_f_menu[i]="$i $e" - i=$((i+1)) - done - fi - _ido_result="${_ido_result/#$HOME\//~/}" -} - -_ido_dir () { - _ido_result=${COMP_WORDS[COMP_CWORD]} - - if [[ "$_ido_result" == \$* ]]; then - if [[ "$_ido_result" == */* ]];then - local temp - temp=${_ido_result%%/*} - temp=${temp#?} - _ido_result=${!temp}/${_ido_result#*/} - else - COMPREPLY=( $( compgen -v -P '$' -- "${_ido_result#$}" ) ) - return 0 - fi - fi - stty intr undef - local status - unset _ido_f_menu _ido_search_string _ido_history_point - printf '\E7' #tput sc = save cursor - status=0 - case $_ido_result in - ''|.|./ ) - _ido_result=$PWD/ - ;; - */*) - _ido_search_string=${_ido_result##*/} - _ido_result=${_ido_result%/*}/ - _ido_result=${_ido_result/#~\//$HOME/} - if [[ ! -d ${_ido_result} ]]; then - printf "\a\nNo Such Directory: %s\n" "${_ido_result}" >&2 - status=1 - fi - ;; - *) - _ido_search_string=$_ido_result - _ido_result=$PWD/ - ;; - esac - # normalize ie remove the // and other foo/../bar - _ido_result=$(command cd "$_ido_result" && printf "%q" "${PWD%/}/") - while [[ $status = 0 && $_ido_result != */./ ]]; do - # hmm this part is dir specific...TB generalized.. - case $_ido_result in - # order is important, the last case covers the first ones - /../) - _ido_result=/ - ;; - \~/../) - _ido_result=${HOME%/*}/ - ;; - */../) - _ido_result=${_ido_result%/*/../}/ - ;; - esac - _ido_gen_dir - _ido_loop; status=$? - _ido_search_string="" - - done - printf "\r%*s\E8" $COLUMNS # clear the line, tput rc restore the cursor - kill -WINCH $$ # force bash to redraw - stty intr $'\003' - if [[ $status = 0 ]]; then - # gives the _ido_result to bash - COMPREPLY[0]=${_ido_result%./} - fi - return $status -} - -complete -F _ido_dir -o nospace cd - -cd () { - if command cd "$@";then - _ido_history=($(printf "%s\n" "$PWD" "${_ido_history[@]}" |\ - awk -v s="$_ido_history_size" '!a[$0]++;(i++==s-1){exit}')) - fi -} -### Local Variables: -### mode: shell-script -### End: diff --git a/shell/bash/git-aware-prompt b/shell/bash/git-aware-prompt deleted file mode 160000 index ee81e21..0000000 --- a/shell/bash/git-aware-prompt +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ee81e21a6d9c77e9a12cda61472d57921b3a3b2b diff --git a/shell/bash/prompt.sh b/shell/bash/prompt.sh deleted file mode 100644 index 0e91f90..0000000 --- a/shell/bash/prompt.sh +++ /dev/null @@ -1,14 +0,0 @@ -# -# Bash Prompt -# - -# Setup and use git-aware-prompt -if [ -f "$DOTBASH/git-aware-prompt/main.sh" ]; then - GITAWAREPROMPT="$DOTBASH/git-aware-prompt" - source "$GITAWAREPROMPT/main.sh" - export PS1="\u@\h \w \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ " - export SUDO_PS1="\[$bakred\]\u@\h\[$txtrst\] \w\$ " -else - # Customize prompt to act like pre-leopard - PS1='\h:\w \u$ ' -fi diff --git a/shell/bashrc.sh b/shell/bashrc.sh deleted file mode 100644 index 721aad2..0000000 --- a/shell/bashrc.sh +++ /dev/null @@ -1,14 +0,0 @@ -# -# Bash Init -# - -# Deterimine current directory -DOTBASH="$DOTSHELL/bash" - -# bash-completion -if [ -f /usr/local/etc/bash_completion ]; then - source /usr/local/etc/bash_completion -fi - -source "$DOTBASH/prompt.sh" -# source "$DOTBASH/bash-ido.sh" # Disabled for making life complicated diff --git a/shell/env.sh b/shell/env.sh deleted file mode 100644 index a4504a2..0000000 --- a/shell/env.sh +++ /dev/null @@ -1,23 +0,0 @@ -# -# Environment Setup -# - -# Editors -export EDITOR="emacsclient-wrapper" -export GEM_EDITOR="mate" - -# Locale Setup -export LC_ALL="en_US.UTF-8" -export LANG="en_US.UTF-8" - -# ensure bin and sbin paths from /usr/local are in PATH -path_add_after "/usr/local/sbin" "/usr/local/bin" - -# ensure bin and sbin paths from /usr are in PATH -path_add_after "/usr/sbin" "/usr/bin" - -# Add user's bin directory to PATH -path_prepend "$HOME/bin" - -# Add dotfiles' bin directory to PATH -path_prepend "$DOTBIN" diff --git a/shell/helpers.sh b/shell/helpers.sh deleted file mode 100644 index f7b4a11..0000000 --- a/shell/helpers.sh +++ /dev/null @@ -1,8 +0,0 @@ -# -# Helper Functions -# - -DOTHELPERS="$DOTSHELL/helpers" - -# Load helpers -source "$DOTHELPERS/path_helpers.sh" diff --git a/shell/osx.sh b/shell/osx.sh deleted file mode 100644 index 7942017..0000000 --- a/shell/osx.sh +++ /dev/null @@ -1,39 +0,0 @@ -# -# OSX Related -# - -# Fix wifi issues on OS X 10.10.x Yosemite. -# - from: https://medium.com/@mariociabarra/wifried-ios-8-wifi-performance-issues-3029a164ce94 -alias fix_wifi="sudo ifconfig awdl0 down" -alias unfix_wifi="sudo ifconfig awdl0 up" - -# Disable the system built-in cmd+ctrl+d global hotkey to lookup word in -# dictionary on OS X. Must reboot after running. -# - from: ://apple.stackexchange.com/a/114269 -osx-disable-lookup-word-hotkey() { - defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add 70 \ - 'enabled' - echo "Command-Control-D hotkey disabled. Please reboot to take effect." -} - -# Show hidden files in Finder. -show_files() { - defaults write com.apple.finder AppleShowAllFiles YES - killall Finder "/System/Library/CoreServices/Finder.app" -} - -# Don't show hidden files in Finder. -hide_files() { - defaults write com.apple.finder AppleShowAllFiles NO - killall Finder "/System/Library/CoreServices/Finder.app" -} - -# Power management -alias pm-hibernate="sudo pmset -a hibernatemode 25" -alias pm-safesleep="sudo pmset -a hibernatemode 3" -alias pm-sleep="sudo pmset -a hibernatemode 0" - -hibernate() { - sudo pmset -a hibernatemode 25 - sudo pmset sleepnow -} diff --git a/shell/svn.sh b/shell/svn.sh deleted file mode 100644 index ccf828d..0000000 --- a/shell/svn.sh +++ /dev/null @@ -1,3 +0,0 @@ -# Aliases -alias svnadderall="svn status | grep '^?' | cut -b 8- | xargs svn add" -alias svnridallin="svn status | grep '^!' | cut -b 8- | xargs svn remove --keep-local" diff --git a/shell/tmpdir.sh b/shell/tmpdir.sh deleted file mode 100644 index a309496..0000000 --- a/shell/tmpdir.sh +++ /dev/null @@ -1,9 +0,0 @@ -# -# TMPDIR setup -# - -# Ensure TMPDIR is the same for local and remote ssh logins -if [[ $TMPDIR == "/var/folders/"* ]] || [[ $TMPDIR == "" ]]; then - export TMPDIR="/tmp/user-$USER" - mkdir -p "$TMPDIR" -fi diff --git a/shell/zsh/zplug-cache/.gitignore b/shell/zsh/zplug-cache/.gitignore deleted file mode 100644 index aa5ea26..0000000 --- a/shell/zsh/zplug-cache/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -cache/* -repos/* diff --git a/shell/zsh/zplug-cache/repos/.gitkeep b/shell/zsh/zplug-cache/repos/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/shell/zshrc.zsh b/shell/zshrc.zsh deleted file mode 100644 index 1e62d6f..0000000 --- a/shell/zshrc.zsh +++ /dev/null @@ -1,65 +0,0 @@ -# -# Z-Shell Init -# - -# Basic stuff. -DISABLE_AUTO_TITLE="true" - -# Export path variables. -DOTZSH="$DOTSHELL/zsh" -ZPLUG_HOME="$DOTZSH/zplug" -ZPLUG_CACHE_DIR="$DOTZSH/zplug-cache/cache" -ZPLUG_REPOS="$DOTZSH/zplug-cache/repos" - -# Don't wrap these commands in a Bundler wrapper. -UNBUNDLED_COMMANDS=(shotgun) - -# -# zplug -# - -source "$DOTZSH/zplug/init.zsh" -alias zp="zplug" - -zplug "lib/history", from:oh-my-zsh, defer:0 -zplug "jimeh/zsh-peco-history", defer:2 -zplug "plugins/bundler", from:oh-my-zsh -zplug "plugins/git", from:oh-my-zsh -zplug "zsh-users/zsh-completions" -zplug "zsh-users/zsh-autosuggestions" -zplug "zsh-users/zsh-syntax-highlighting", defer:3 - -zplug "jimeh/plain.zsh-theme", as:theme - -# Install plugins if there are plugins that have not been installed -if ! zplug check --verbose; then - printf "Install? [y/N]: " - if read -q; then - echo - zplug install - fi -fi - -# Configure zsh-syntax-highlighting -if zplug check zsh-users/zsh-syntax-highlighting; then - ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets) -fi - -zplug load - -# -# Basic Z-Shell settings -# - -# Enable bash-style completion. -autoload -U +X compinit && compinit -autoload -U +X bashcompinit && bashcompinit - -# Disable shared history. -unsetopt share_history - -# Disable attempted correction of commands (is wrong 98% of the time). -unsetopt correctall - -# Cause I hit emacs shorts too much. -# bindkey -s "\C-x\C-f" "cd " diff --git a/shellrc.sh b/shellrc.sh deleted file mode 100644 index 6359d52..0000000 --- a/shellrc.sh +++ /dev/null @@ -1,24 +0,0 @@ -# -# Shell Init -# - -# Set path to root of dotfiles -if [ -n "${BASH_SOURCE[0]}" ] && [ -f "${BASH_SOURCE[0]}" ] ; then - DOTFILES="`dirname \"${BASH_SOURCE[0]}\"`" -elif [ -n "$0" ] && [ -f "$0" ]; then - DOTFILES="`dirname \"$0\"`" -elif [ -d "$HOME/.dotfiles" ]; then - DOTFILES="$HOME/.dotfiles" -fi - -# Load main dotfiles -DOTSHELL="$DOTFILES/shell" -if [ -f "$DOTSHELL/_main.sh" ]; then - source "$DOTSHELL/_main.sh" -fi - -# Setup and load private dotfiles -DOTPFILES="$DOTFILES/private" -if [ -f "$DOTPFILES/shellrc.sh" ]; then - source "$DOTPFILES/shellrc.sh" -fi diff --git a/shell/tmux/tmuxifier b/tmux/tmuxifier similarity index 100% rename from shell/tmux/tmuxifier rename to tmux/tmuxifier diff --git a/shell/aliases.sh b/zsh/aliases.zsh similarity index 100% rename from shell/aliases.sh rename to zsh/aliases.zsh diff --git a/shell/docker.sh b/zsh/docker.zsh similarity index 100% rename from shell/docker.sh rename to zsh/docker.zsh diff --git a/shell/emacs.sh b/zsh/emacs.zsh similarity index 100% rename from shell/emacs.sh rename to zsh/emacs.zsh diff --git a/shell/git.sh b/zsh/git.zsh similarity index 100% rename from shell/git.sh rename to zsh/git.zsh diff --git a/shell/golang.sh b/zsh/golang.zsh similarity index 100% rename from shell/golang.sh rename to zsh/golang.zsh diff --git a/shell/google-cloud.sh b/zsh/google-cloud.zsh similarity index 100% rename from shell/google-cloud.sh rename to zsh/google-cloud.zsh diff --git a/shell/kubernetes.sh b/zsh/kubernetes.zsh similarity index 100% rename from shell/kubernetes.sh rename to zsh/kubernetes.zsh diff --git a/shell/less.sh b/zsh/less.zsh similarity index 100% rename from shell/less.sh rename to zsh/less.zsh diff --git a/zsh/linux.zsh b/zsh/linux.zsh new file mode 100644 index 0000000..26d610a --- /dev/null +++ b/zsh/linux.zsh @@ -0,0 +1,8 @@ +# +# Linux specific setup +# + +# Ensure 256 color support in Linux +if [[ "$(uname)" == "Linux" ]]; then + export TERM="xterm-256color" +fi diff --git a/shell/nodejs.sh b/zsh/nodejs.zsh similarity index 100% rename from shell/nodejs.sh rename to zsh/nodejs.zsh diff --git a/zsh/osx.zsh b/zsh/osx.zsh new file mode 100644 index 0000000..343eb16 --- /dev/null +++ b/zsh/osx.zsh @@ -0,0 +1,41 @@ +# +# OSX Related +# + +if [[ "$(uname)" == "Darwin" ]]; then + # Fix wifi issues on OS X 10.10.x Yosemite. + # - from: https://medium.com/@mariociabarra/wifried-ios-8-wifi-performance-issues-3029a164ce94 + alias fix_wifi="sudo ifconfig awdl0 down" + alias unfix_wifi="sudo ifconfig awdl0 up" + + # Disable the system built-in cmd+ctrl+d global hotkey to lookup word in + # dictionary on OS X. Must reboot after running. + # - from: ://apple.stackexchange.com/a/114269 + osx-disable-lookup-word-hotkey() { + defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add 70 \ + 'enabled' + echo "Command-Control-D hotkey disabled. Please reboot to take effect." + } + + # Show hidden files in Finder. + show_files() { + defaults write com.apple.finder AppleShowAllFiles YES + killall Finder "/System/Library/CoreServices/Finder.app" + } + + # Don't show hidden files in Finder. + hide_files() { + defaults write com.apple.finder AppleShowAllFiles NO + killall Finder "/System/Library/CoreServices/Finder.app" + } + + # Power management + alias pm-hibernate="sudo pmset -a hibernatemode 25" + alias pm-safesleep="sudo pmset -a hibernatemode 3" + alias pm-sleep="sudo pmset -a hibernatemode 0" + + hibernate() { + sudo pmset -a hibernatemode 25 + sudo pmset sleepnow + } +fi diff --git a/shell/helpers/path_helpers.sh b/zsh/path_helpers.zsh similarity index 100% rename from shell/helpers/path_helpers.sh rename to zsh/path_helpers.zsh diff --git a/shell/ruby.sh b/zsh/ruby.zsh similarity index 100% rename from shell/ruby.sh rename to zsh/ruby.zsh diff --git a/shell/rust.sh b/zsh/rust.zsh similarity index 100% rename from shell/rust.sh rename to zsh/rust.zsh diff --git a/shell/tmux.sh b/zsh/tmux.zsh similarity index 72% rename from shell/tmux.sh rename to zsh/tmux.zsh index f27cdda..1ce80f6 100644 --- a/shell/tmux.sh +++ b/zsh/tmux.zsh @@ -16,13 +16,14 @@ if [ -f "/usr/local/etc/bash_completion.d/tmux" ]; then fi # Tmuxifier -if [ -d "$DOTSHELL/tmux/tmuxifier" ]; then - if [ -d "$HOME/.dotfiles/private/tmux-layouts" ]; then - export TMUXIFIER_LAYOUT_PATH="$HOME/.dotfiles/private/tmux-layouts" +if [ -d "$DOTFILES/tmux/tmuxifier" ]; then + if [ -d "$DOTPFILES/tmux-layouts" ]; then + export TMUXIFIER_LAYOUT_PATH="$DOTPFILES/tmux-layouts" else export TMUXIFIER_LAYOUT_PATH="$HOME/.tmux-layouts" fi - path_prepend "$DOTSHELL/tmux/tmuxifier/bin" + + path_prepend "$DOTFILES/tmux/tmuxifier/bin" eval "$(tmuxifier init -)" alias m="tmuxifier" @@ -33,6 +34,6 @@ fi use-tmuxifier-dev() { path_prepend "$HOME/Projects/tmuxifier/bin" - path_remove "$DOTSHELL/tmux/tmuxifier/bin" + path_remove "$DOTFILES/tmux/tmuxifier/bin" export TMUXIFIER="$HOME/Projects/tmuxifier" } diff --git a/shell/zsh/plugins/.gitkeep b/zsh/zplug/cache/.gitkeep similarity index 100% rename from shell/zsh/plugins/.gitkeep rename to zsh/zplug/cache/.gitkeep diff --git a/shell/zsh/zplug-cache/cache/.gitkeep b/zsh/zplug/repos/.gitkeep similarity index 100% rename from shell/zsh/zplug-cache/cache/.gitkeep rename to zsh/zplug/repos/.gitkeep diff --git a/shell/zsh/zplug b/zsh/zplug/zplug similarity index 100% rename from shell/zsh/zplug rename to zsh/zplug/zplug diff --git a/zshrc.zsh b/zshrc.zsh new file mode 100644 index 0000000..750d7fc --- /dev/null +++ b/zshrc.zsh @@ -0,0 +1,134 @@ +# +# Z-Shell Init +# + +if [ -n "$0" ] && [ -f "$0" ]; then + DOTFILES="`dirname \"$0\"`" +elif [ -d "$HOME/.dotfiles" ]; then + DOTFILES="$HOME/.dotfiles" +fi + +# ============================================================================== +# Environment variables +# ============================================================================== + +# Export path variables. +DOTPFILES="$DOTFILES/private" +DOTBIN="$DOTFILES/bin" +DOTZSH="$DOTFILES/zsh" + +# Path helpers. +source "$DOTZSH/path_helpers.zsh" + +# Ensure /usr/local/bin is before various system-paths +path_prepend "/usr/local/bin" + +# Editors +export EDITOR="emacsclient-wrapper" +export GEM_EDITOR="mate" + +# Locale Setup +export LC_ALL="en_US.UTF-8" +export LANG="en_US.UTF-8" + +# ensure bin and sbin paths from /usr/local are in PATH +path_add_after "/usr/local/sbin" "/usr/local/bin" + +# ensure bin and sbin paths from /usr are in PATH +path_add_after "/usr/sbin" "/usr/bin" + +# Add user's bin directory to PATH +path_prepend "$HOME/bin" + +# Add dotfiles' bin directory to PATH +path_prepend "$DOTBIN" + +# Ensure TMPDIR is the same for local and remote ssh logins +if [[ $TMPDIR == "/var/folders/"* ]] || [[ $TMPDIR == "" ]]; then + export TMPDIR="/tmp/user-$USER" + mkdir -p "$TMPDIR" +fi + +# ============================================================================== +# Basic Z-Shell settings +# ============================================================================== + +# Disable auto-title. +DISABLE_AUTO_TITLE="true" + +# Enable bash-style completion. +autoload -U +X compinit && compinit +autoload -U +X bashcompinit && bashcompinit + +# Disable shared history. +unsetopt share_history + +# Disable attempted correction of commands (is wrong 98% of the time). +unsetopt correctall + +# ============================================================================== +# zplug +# ============================================================================== + +ZPLUG_HOME="$DOTZSH/zplug/zplug" +ZPLUG_CACHE_DIR="$DOTZSH/zplug/cache" +ZPLUG_REPOS="$DOTZSH/zplug/repos" + +source "$ZPLUG_HOME/init.zsh" +alias zp="zplug" + +zplug "lib/history", from:oh-my-zsh, defer:1 +zplug "jimeh/zsh-peco-history", defer:2 +zplug "plugins/bundler", from:oh-my-zsh +zplug "plugins/git", from:oh-my-zsh +zplug "zsh-users/zsh-completions" +zplug "zsh-users/zsh-autosuggestions" +zplug "zsh-users/zsh-syntax-highlighting", defer:3 + +zplug "jimeh/plain.zsh-theme", as:theme + +# Install plugins if there are plugins that have not been installed +if ! zplug check --verbose; then + printf "Install? [y/N]: " + if read -q; then + echo + zplug install + fi +fi + +# Configure zsh-syntax-highlighting +if zplug check zsh-users/zsh-syntax-highlighting; then + ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets) +fi + +zplug load + +# ============================================================================== +# Load custom scripts +# ============================================================================== + +# Aliases +source "$DOTZSH/aliases.zsh" + +# OS specific +source "$DOTZSH/osx.zsh" +source "$DOTZSH/linux.zsh" + +# Utils +source "$DOTZSH/emacs.zsh" +source "$DOTZSH/git.zsh" +source "$DOTZSH/tmux.zsh" +source "$DOTZSH/less.zsh" + +# Development +source "$DOTZSH/nodejs.zsh" +source "$DOTZSH/ruby.zsh" +source "$DOTZSH/rust.zsh" +source "$DOTZSH/golang.zsh" +source "$DOTZSH/docker.zsh" +source "$DOTZSH/google-cloud.zsh" +source "$DOTZSH/kubernetes.zsh" + +if [ -f "$DOTPFILES/shellrc.sh" ]; then + source "$DOTPFILES/shellrc.sh" +fi