From a1f12f614b4b8963e90a8bac9d06e2c682202855 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Sun, 22 Jan 2017 18:25:39 +0100 Subject: [PATCH] Fully replace bash with zsh Signed-off-by: Tomas Slusny --- .gitmodules | 9 +- README.md | 8 +- dotfiles/bash_profile | 11 -- dotfiles/bashrc | 259 ----------------------------------- dotfiles/zimrc | 4 +- dotfiles/zshrc | 126 ++++++++--------- install.conf.yaml | 5 - lib/shell/fasd | 1 - lib/shell/vi-mode.plugin.zsh | 49 +++++++ lib/shell/zim | 2 +- lib/vim/vim-snippets | 2 +- 11 files changed, 122 insertions(+), 354 deletions(-) delete mode 100644 dotfiles/bash_profile delete mode 100644 dotfiles/bashrc delete mode 160000 lib/shell/fasd create mode 100644 lib/shell/vi-mode.plugin.zsh diff --git a/.gitmodules b/.gitmodules index be7196a4..4ae193bd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,10 +4,7 @@ [submodule "lib/bash/bash-it"] path = lib/bash/bash-it url = https://github.com/Bash-it/bash-it -[submodule "lib/bash/fasd"] - path = lib/shell/fasd - url = https://github.com/clvv/fasd -[submodule "lib/bash/fzf"] +[submodule "lib/shell/fzf"] path = lib/shell/fzf url = https://github.com/junegunn/fzf.git [submodule "lib/vim-pathogen"] @@ -37,7 +34,7 @@ [submodule "lib/vim/base16-vim"] path = lib/vim/base16-vim url = https://github.com/chriskempson/base16-vim -[submodule "lib/bash/base16-shell"] +[submodule "lib/shell/base16-shell"] path = lib/shell/base16-shell url = https://github.com/chriskempson/base16-shell [submodule "lib/tmux/tmux-yank"] @@ -93,4 +90,4 @@ url = https://github.com/tmux-plugins/tmux-open [submodule "lib/shell/zim"] path = lib/shell/zim - url = https://github.com/Eriner/zim + url = https://github.com/deathbeam/zim diff --git a/README.md b/README.md index 9779166b..e1bf1c27 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,8 @@ because most of the time I just cannot make up my mind, and I change my decision ## Optional requirements -* bash - I am using bash, and my terminal configuration is working mostly for bash only. If you are using zsh, or fish - or whatever, it's okay, I tried them all and eventually I came back to bash, mainly because some completion stuff I am - using is a bit broken in other shells than bash. Otherwise, zsh is really great and if all this completion stuff was - properly working there, I would be using zsh. +* zsh - Zsh is awesome. I was using bash, but then switched to zsh, and it is pretty much compatible with all bash stuff + and it is also faster and nicer. * [tmux](https://tmux.github.io/) - Terminal multiplexer. Awesome stuff, but I find myself to use it less and less, because I started using tiling window manager's features more. But still, tmux is really awesome, and have some great features what screen do not have. I have some really nice Tmux stuff in my repository, so feel free to try it, maybe @@ -130,7 +128,7 @@ To see all helper commands, run `dottool --help`. ## Included stuff ### Shell - * [fasd](https://github.com/clvv/fasd): Command-line productivity booster, offers quick access to files and directories, inspired by autojump, z and v. + * [zim](https://github.com/Eriner/zim): ZIM - Zsh IMproved * [fzf](https://github.com/junegunn/fzf): A command-line fuzzy finder written in Go * [base-16-shell](https://github.com/chriskempson/base16-shell): A shell script to change your shell's default ANSI colors but most importantly, colors 17 to 21 of your shell's 256 colorspace (if supported by your terminal) diff --git a/dotfiles/bash_profile b/dotfiles/bash_profile deleted file mode 100644 index d638a268..00000000 --- a/dotfiles/bash_profile +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -# Load base .profile (in some environments, if .bash_profile is being loaded, .profile loading is skipped, we do not want that) -if [ -f ~/.profile ]; then - source ~/.profile -fi - -# Load .bashrc (in some environments, .bashrc is not loaded when running login shell, so fix it) -if [ -f ~/.bashrc ]; then - source ~/.bashrc -fi diff --git a/dotfiles/bashrc b/dotfiles/bashrc deleted file mode 100644 index 2cc5cf97..00000000 --- a/dotfiles/bashrc +++ /dev/null @@ -1,259 +0,0 @@ -#!/usr/bin/env bash -# vim:set ft=sh:foldmethod=marker: -# ██████╗ █████╗ ███████╗██╗ ██╗██████╗ ██████╗ -# ██╔══██╗██╔══██╗██╔════╝██║ ██║██╔══██╗██╔════╝ -# ██████╔╝███████║███████╗███████║██████╔╝██║ -# ██╔══██╗██╔══██║╚════██║██╔══██║██╔══██╗██║ -# ██████╔╝██║ ██║███████║██║ ██║██║ ██║╚██████╗ -# ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ - -# General {{{ - # If not running interactively, don't continue - [ -z "$PS1" ] && return - - if [ -f /etc/bashrc ]; then - . /etc/bashrc # --> Read /etc/bashrc, if present. - fi - - # Case-insensitive globbing (used in pathname expansion) - shopt -s nocaseglob; - - # Autocorrect typos in path names when using `cd` - shopt -s cdspell; - - # Enable some Bash 4 features when possible: - # * `autocd`, e.g. `**/qux` will enter `./foo/bar/baz/qux` - # * Recursive globbing, e.g. `echo **/*.txt` - for option in autocd globstar; do - shopt -s "$option" 2> /dev/null; - done; - - # Better history - shopt -s histappend - shopt -s cmdhist - export HISTFILESIZE=1000000 - export HISTSIZE=1000000 - export HISTCONTROL=ignoreboth:erasedups - export HISTIGNORE='ls:bg:fg:history' - export HISTTIMEFORMAT='%F %T ' - [[ "$PROMPT_COMMAND" != "*history*" ]] && export PROMPT_COMMAND="history -a;$PROMPT_COMMAND" - -# }}} - -# User interface {{{ - - # Set custom prompt with git info included when available - source ~/.git-prompt.sh - _PS1 () - { - local PRE= NAME="$1" LENGTH="$2"; - [[ "$NAME" != "${NAME#$HOME/}" || -z "${NAME#$HOME}" ]] && - PRE+='~' NAME="${NAME#$HOME}" LENGTH=$[LENGTH-1]; - ((${#NAME}>$LENGTH)) && NAME="/...${NAME:$[${#NAME}-LENGTH+4]}"; - echo "$PRE$NAME" - } - - # If we are not connected through SSH or TTY, use custom PS1 - if [ -z "$SSH_CLIENT" ] && [ -z "$SSH_TTY" ]; then - export PS1='$(_PS1 "$PWD" 20)$(__git_ps1) \[\e[31;1m\]❯\[\e[0m\]\[\e[33;1m\]❯\[\e[0m\]\[\e[32;1m\]❯\[\e[0m\] ' - fi - - # Load bash_completion (it is important to load it before fzf) - if command -v brew >/dev/null 2>&1; then - if [ -f $(brew --prefix)/etc/bash_completion ]; then - source $(brew --prefix)/etc/bash_completion - fi - else - if [ -f /usr/share/bash-completion/bash_completion ]; then - . /usr/share/bash-completion/bash_completion - elif [ -f /etc/bash_completion ]; then - . /etc/bash_completion - fi - fi - - # Add tab completion for SSH hostnames based on ~/.ssh/config, ignoring wildcards - [ -e "$HOME/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2- | tr ' ' '\n')" scp sftp ssh; - -# }}} - -# Aliases and functions {{{ - - # Pretty-print of PATH variables - alias path='echo -e ${PATH//:/\\n}' - - # Some sane aliases - alias mkdir='mkdir -p' - alias ..='cd ..' - - # Detect which `ls` flavor is in use - if ls --color > /dev/null 2>&1; then # GNU `ls` - colorflag="--color" - else # OS X `ls` - colorflag="-G" - fi - - # Add colors for filetype and human-readable sizes by default on 'ls': - alias ls="ls -h ${colorflag}" - alias lk='ls -lSr' # Sort by size, biggest last. - alias lt='ls -ltr' # Sort by date, most recent last. - alias lc='ls -ltcr' # Sort by/show change time,most recent last. - alias lu='ls -ltur' # Sort by/show access time,most recent last. - - # The ubiquitous 'll' - alias ll="ls -lG" - alias lm='ll | more' # Pipe through 'more' - alias lr='ll -R' # Recursive ls. - alias la='ll -A' # Show hidden files. - alias tree='tree -Csuh' # Nice alternative to 'recursive ls' ... - - # Update and cleanup brew - if command -v brew >/dev/null 2>&1; then - export PYTHONPATH=$(brew --prefix)/lib/python2.7/site-packages:$PYTHONPATH - alias brewup='brew update && brew upgrade --all && brew cleanup && brew cask cleanup' - fi - - # Copy-paste (requires xclip on *NIX systems) - if command -v xclip >/dev/null 2>&1; then - alias pbcopy='xclip -i -selection clipboard' - alias pbpaste='xclip -o -selection clipboard' - fi - - # Enhanced WHOIS lookups - alias whois="whois -h whois-servers.net" - - # Run with in server mode to allow eclim debugger, open eclim project and start session recording - function vjava () { - $EDITOR --servername "$1" +Session +"ProjectOpen $1" - } - - # Serve current directory as HTTP server, optionally specifying the port (default is 8000) - function serve() { - local port="${1:-8000}" - sleep 1 && open "http://localhost:${port}/" & - # Set the default Content-Type to `text/plain` instead of `application/octet-stream` - # And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files) - python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port" - } - - # Handy Extract Program - function extract() { - if [ -f $1 ] ; then - case $1 in - *.tar.bz2) tar xvjf $1 ;; - *.tar.gz) tar xvzf $1 ;; - *.bz2) bunzip2 $1 ;; - *.rar) unrar x $1 ;; - *.gz) gunzip $1 ;; - *.tar) tar xvf $1 ;; - *.tbz2) tar xvjf $1 ;; - *.tgz) tar xvzf $1 ;; - *.zip) unzip $1 ;; - *.Z) uncompress $1 ;; - *.7z) 7z x $1 ;; - *) echo "'$1' cannot be extracted via >extract<" ;; - esac - else - echo "'$1' is not a valid file!" - fi - } - - # Creates an archive (*.tar.gz) from given directory. - function maketar() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; } - - # Create a ZIP archive of a file or folder. - function makezip() { zip -r "${1%%/}.zip" "$1" ; } - - # Make your directories and files access rights sane. - function sanitize() { chmod -R u=rwX,g=rX,o= "$@" ;} - -# }}} - -# Colors {{{ - - # Enable colors - export CLICOLOR=1 - - # Enable 256 color mode - # [[ $TMUX = "" ]] && export TERM="xterm-256color" - - # Base 16 - BASE16_SHELL=$DOTHOME/lib/shell/base16-shell/ - [ -s $BASE16_SHELL/profile_helper.sh ] && eval "$($BASE16_SHELL/profile_helper.sh)" - [ -z $BASE16_THEME ] && base16_tomorrow-night - -# }}} - -# Plugins {{{ - - # Init fasd with cache to speed up startup - source "$DOTHOME/lib/shell/fasd/fasd" > /dev/null - fasd_cache=~/.fasd.cache.bash - if [ "$(command -v fasd)" -nt "$fasd_cache" -o ! -s "$fasd_cache" ]; then - fasd --init posix-alias bash-hook bash-ccomp bash-ccomp-install >| "$fasd_cache" - fi - source "$fasd_cache" - unset fasd_cache - - # Add viminfo fasd command - alias v='f -e vim -b viminfo' - _fasd_bash_hook_cmd_complete v - - # Load fzf - source ~/.fzf.bash - - # Use faster grep command if possible - if command -v rg >/dev/null 2>&1; then - export FZF_DEFAULT_COMMAND='rg --files --hidden --follow --glob "!.git/*"' - elif command -v ag >/dev/null 2>&1; then - export FZF_DEFAULT_COMMAND='ag -g ""' - fi - - # Load rest of libraries - # command -v thefuck >/dev/null 2>&1 && eval "$(thefuck --alias)" - command -v hub >/dev/null 2>&1 && eval "$(hub alias -s)" - -# }}} - -# User configuration {{{ - - # Simple helper to manage dotfiles setup - dottool() { - case ${1} in - # Update dotfiles - -u|--update) - git -C "$DOTHOME" pull --rebase - eval "$DOTHOME/install" - ;; - # Fast open and edit user rc files - -o|--open) - eval "$EDITOR $DOTHOME/usr/$2" - ;; - # Add link to $DOTHOME/usr/bin what is added to $PATH - -l|--link) - local name=`basename $2` - local curpath="$PWD/$2" - ln -s $curpath "$DOTHOME/usr/bin/$name" - ;; - # Add Vim plugin as submodule - -v|--vim-plugin) - (cd "$DOTHOME/usr/vim"; git clone "$2") - ;; - -h|--help) - echo -e "usage: " - echo -e "\t-u | --update update adrc" - echo -e "\t-o | --open fast open and edit confiuration files (bashrc, vimrc, tmux.conf, gitconfig)" - echo -e "\t-l | --link add link to $DOTHOME/usr/bin what is in \$PATH variable (useful for adding CLI things)" - echo -e "\t-v | --vim-plugin add vim plugin as git submodule to $DOTHOME/usr/vim" - echo -e "\t-h | --help show this message" - ;; - *) - echo "Wrong command '${1}'. See --help" - ;; - esac - } - - # Load user config - [[ -f "$DOTHOME/usr/bashrc" ]] && - source "$DOTHOME/usr/bashrc" - -# }}} diff --git a/dotfiles/zimrc b/dotfiles/zimrc index c050be84..151df4f5 100644 --- a/dotfiles/zimrc +++ b/dotfiles/zimrc @@ -1,9 +1,9 @@ # Select what modules you would like enabled. -zmodules=(directory environment git git-info history input utility meta custom \ +zmodules=(directory environment fasd git git-info history input utility meta \ syntax-highlighting history-substring-search prompt completion) # Set your desired prompt here -zprompt_theme='gitster' +zprompt_theme='pure' # Set the string below to the desired terminal title format string. # Below uses the following format: 'username@host:/current/directory' diff --git a/dotfiles/zshrc b/dotfiles/zshrc index 96d4fa16..bad93838 100644 --- a/dotfiles/zshrc +++ b/dotfiles/zshrc @@ -1,76 +1,76 @@ -# Source .profile -if [ -f ~/.profile ]; then - source ~/.profile -fi +# vim:foldmethod=marker:set ft=zsh: -# Colors {{{ +# General {{{ + + # Source .profile + if [ -f ~/.profile ]; then + source ~/.profile + fi # Enable colors export CLICOLOR=1 - # Enable 256 color mode - # [[ $TMUX = "" ]] && export TERM="xterm-256color" +# }}} + +# Aliases & functions {{{ + + # Update and cleanup brew + if command -v brew >/dev/null 2>&1; then + export PYTHONPATH=$(brew --prefix)/lib/python2.7/site-packages:$PYTHONPATH + alias brewup='brew update && brew upgrade --all && brew cleanup && brew cask cleanup' + fi + + # Copy-paste (requires xclip on *NIX systems) + if command -v xclip >/dev/null 2>&1; then + alias pbcopy='xclip -i -selection clipboard' + alias pbpaste='xclip -o -selection clipboard' + fi + + # Run with in server mode to allow eclim debugger, open eclim project and start session recording + function vjava () { + $EDITOR --servername "$1" +Session +"ProjectOpen $1" + } + +# }}} + +# Plugins {{{ + + # Source zim + if [[ -s ${ZDOTDIR:-${HOME}}/.zim/init.zsh ]]; then + source ${ZDOTDIR:-${HOME}}/.zim/init.zsh + fi + + # Load vi mode plugin + source "$DOTHOME/lib/shell/vi-mode.plugin.zsh" # Base 16 BASE16_SHELL=$DOTHOME/lib/shell/base16-shell/ [ -s $BASE16_SHELL/profile_helper.sh ] && eval "$($BASE16_SHELL/profile_helper.sh)" [ -z $BASE16_THEME ] && base16_tomorrow-night + # Add viminfo fasd command + alias v='f -e vim -b viminfo' + + # Load fzf + source ~/.fzf.zsh + + # Use faster grep command if possible + if command -v rg >/dev/null 2>&1; then + export FZF_DEFAULT_COMMAND='rg --files --hidden --follow --glob "!.git/*"' + elif command -v ag >/dev/null 2>&1; then + export FZF_DEFAULT_COMMAND='ag -g ""' + fi + + # Load rest of libraries + # command -v thefuck >/dev/null 2>&1 && eval "$(thefuck --alias)" + command -v hub >/dev/null 2>&1 && eval "$(hub alias -s)" + # }}} -# Source zim -if [[ -s ${ZDOTDIR:-${HOME}}/.zim/init.zsh ]]; then - source ${ZDOTDIR:-${HOME}}/.zim/init.zsh -fi - -# Update and cleanup brew -if command -v brew >/dev/null 2>&1; then - export PYTHONPATH=$(brew --prefix)/lib/python2.7/site-packages:$PYTHONPATH - alias brewup='brew update && brew upgrade --all && brew cleanup && brew cask cleanup' -fi - -# Copy-paste (requires xclip on *NIX systems) -if command -v xclip >/dev/null 2>&1; then - alias pbcopy='xclip -i -selection clipboard' - alias pbpaste='xclip -o -selection clipboard' -fi - -# Run with in server mode to allow eclim debugger, open eclim project and start session recording -function vjava () { - $EDITOR --servername "$1" +Session +"ProjectOpen $1" -} - -# Serve current directory as HTTP server, optionally specifying the port (default is 8000) -function serve() { - local port="${1:-8000}" - sleep 1 && open "http://localhost:${port}/" & - # Set the default Content-Type to `text/plain` instead of `application/octet-stream` - # And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files) - python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port" -} - -# Init fasd with cache to speed up startup -source "$DOTHOME/lib/shell/fasd/fasd" > /dev/null -fasd_cache=~/.fasd.cache.zsh -if [ "$(command -v fasd)" -nt "$fasd_cache" -o ! -s "$fasd_cache" ]; then - fasd --init posix-alias zsh-hook zsh-ccomp zsh-ccomp-install zsh-wcomp zsh-wcomp-install >| "$fasd_cache" -fi -source "$fasd_cache" -unset fasd_cache - -# Add viminfo fasd command -alias v='f -e vim -b viminfo' - -# Load fzf -source ~/.fzf.zsh - -# Use faster grep command if possible -if command -v rg >/dev/null 2>&1; then - export FZF_DEFAULT_COMMAND='rg --files --hidden --follow --glob "!.git/*"' -elif command -v ag >/dev/null 2>&1; then - export FZF_DEFAULT_COMMAND='ag -g ""' -fi - -# Load rest of libraries -# command -v thefuck >/dev/null 2>&1 && eval "$(thefuck --alias)" -command -v hub >/dev/null 2>&1 && eval "$(hub alias -s)" +# User configuration {{{ + + # Load user config + [[ -f "$DOTHOME/usr/zshrc" ]] && + source "$DOTHOME/usr/zshrc" + +# }}} diff --git a/install.conf.yaml b/install.conf.yaml index d7bcf23c..884f9819 100644 --- a/install.conf.yaml +++ b/install.conf.yaml @@ -20,9 +20,6 @@ - - 'echo "export DOTHOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"" > usr/dotconfig; touch usr/gitconfig' - Setting up home directory - - - - curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -o ~/.git-prompt.sh - - Downloading git prompt - - lib/shell/fzf/install --all --no-update-rc - Installing fuzzy finder for shell @@ -33,8 +30,6 @@ - link: $HOME/.dotconfig: usr/dotconfig $HOME/.profile: dotfiles/profile - $HOME/.bash_profile: dotfiles/bash_profile - $HOME/.bashrc: dotfiles/bashrc $HOME/.vimrc: dotfiles/vimrc $HOME/.tmux.conf: dotfiles/tmux.conf $HOME/.ideavimrc: dotfiles/ideavimrc diff --git a/lib/shell/fasd b/lib/shell/fasd deleted file mode 160000 index 90b531a5..00000000 --- a/lib/shell/fasd +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 90b531a5daaa545c74c7d98974b54cbdb92659fc diff --git a/lib/shell/vi-mode.plugin.zsh b/lib/shell/vi-mode.plugin.zsh new file mode 100644 index 00000000..a28f7d43 --- /dev/null +++ b/lib/shell/vi-mode.plugin.zsh @@ -0,0 +1,49 @@ +# Updates editor information when the keymap changes. +function zle-keymap-select() { + zle reset-prompt + zle -R +} + +# Ensure that the prompt is redrawn when the terminal size changes. +TRAPWINCH() { + zle && zle -R +} + +zle -N zle-keymap-select +zle -N edit-command-line + +bindkey -v + +# allow v to edit the command line (standard behaviour) +autoload -Uz edit-command-line +bindkey -M vicmd 'v' edit-command-line + +# allow ctrl-p, ctrl-n for navigate history (standard behaviour) +bindkey '^P' up-history +bindkey '^N' down-history + +# allow ctrl-h, ctrl-w, ctrl-? for char and word deletion (standard behaviour) +bindkey '^?' backward-delete-char +bindkey '^h' backward-delete-char +bindkey '^w' backward-kill-word + +# allow ctrl-r to perform backward search in history +bindkey '^r' history-incremental-search-backward + +# allow ctrl-a and ctrl-e to move to beginning/end of line +bindkey '^a' beginning-of-line +bindkey '^e' end-of-line + +# if mode indicator wasn't setup by theme, define default +if [[ "$MODE_INDICATOR" == "" ]]; then + MODE_INDICATOR="%{$fg_bold[red]%}<%{$fg[red]%}<<%{$reset_color%}" +fi + +function vi_mode_prompt_info() { + echo "${${KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/}" +} + +# define right prompt, if it wasn't defined by a theme +if [[ "$RPS1" == "" && "$RPROMPT" == "" ]]; then + RPS1='$(vi_mode_prompt_info)' +fi diff --git a/lib/shell/zim b/lib/shell/zim index cc34e3f3..d5536d60 160000 --- a/lib/shell/zim +++ b/lib/shell/zim @@ -1 +1 @@ -Subproject commit cc34e3f310aa6c0e532c70a739b081b89569571f +Subproject commit d5536d607f5c593e9f827ec005f3e09a486e65f3 diff --git a/lib/vim/vim-snippets b/lib/vim/vim-snippets index 40ca4aec..acfd5938 160000 --- a/lib/vim/vim-snippets +++ b/lib/vim/vim-snippets @@ -1 +1 @@ -Subproject commit 40ca4aec34d457d29e4e731b14cc3328c9f27009 +Subproject commit acfd5938d623b81145f65cd0b42861a49c05cc4e