diff options
-rw-r--r-- | lib/git.zsh | 21 | ||||
-rw-r--r-- | plugins/archlinux/archlinux.plugin.zsh | 2 | ||||
-rw-r--r-- | plugins/brew/_brew | 31 | ||||
-rw-r--r-- | plugins/coffee/README.md | 2 | ||||
-rw-r--r-- | plugins/docker-compose/docker-compose.plugin.zsh | 13 | ||||
-rw-r--r-- | plugins/droplr/README.md | 19 | ||||
-rw-r--r-- | plugins/droplr/droplr.plugin.zsh | 15 | ||||
-rw-r--r-- | plugins/firewalld/firewalld.plugin.zsh | 17 | ||||
-rw-r--r-- | plugins/firewalld/readme.md | 22 | ||||
-rw-r--r-- | plugins/git/git.plugin.zsh | 6 | ||||
-rw-r--r-- | plugins/lein/lein.plugin.zsh | 2 | ||||
-rw-r--r-- | plugins/npm/npm.plugin.zsh | 7 | ||||
-rw-r--r-- | plugins/ssh-agent/README.md | 38 | ||||
-rw-r--r-- | plugins/ssh-agent/ssh-agent.plugin.zsh | 93 | ||||
-rw-r--r-- | plugins/vi-mode/vi-mode.plugin.zsh | 9 |
15 files changed, 215 insertions, 82 deletions
diff --git a/lib/git.zsh b/lib/git.zsh index 648a766b5..f7eccb81d 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -76,16 +76,21 @@ function git_current_branch() { # Gets the number of commits ahead from remote function git_commits_ahead() { - if $(command git rev-parse --git-dir > /dev/null 2>&1); then - local COMMITS="$(git rev-list --count @{upstream}..HEAD)" - echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$COMMITS$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX" + if command git rev-parse --git-dir &>/dev/null; then + local commits="$(git rev-list --count @{upstream}..HEAD)" + if [[ "$commits" != 0 ]]; then + echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$commits$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX" + fi fi } # Gets the number of commits behind remote function git_commits_behind() { - if $(command git rev-parse --git-dir > /dev/null 2>&1); then - echo $(git rev-list --count HEAD..@{upstream}) + if command git rev-parse --git-dir &>/dev/null; then + local commits="$(git rev-list --count HEAD..@{upstream})" + if [[ "$commits" != 0 ]]; then + echo "$ZSH_THEME_GIT_COMMITS_BEHIND_PREFIX$commits$ZSH_THEME_GIT_COMMITS_BEHIND_SUFFIX" + fi fi } @@ -160,13 +165,13 @@ function git_prompt_status() { if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS" fi - if $(echo "$INDEX" | grep '^## .*ahead' &> /dev/null); then + if $(echo "$INDEX" | grep '^## [^ ]\+ .*ahead' &> /dev/null); then STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS" fi - if $(echo "$INDEX" | grep '^## .*behind' &> /dev/null); then + if $(echo "$INDEX" | grep '^## [^ ]\+ .*behind' &> /dev/null); then STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS" fi - if $(echo "$INDEX" | grep '^## .*diverged' &> /dev/null); then + if $(echo "$INDEX" | grep '^## [^ ]\+ .*diverged' &> /dev/null); then STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$STATUS" fi echo $STATUS diff --git a/plugins/archlinux/archlinux.plugin.zsh b/plugins/archlinux/archlinux.plugin.zsh index 9c8c984b1..1637e8561 100644 --- a/plugins/archlinux/archlinux.plugin.zsh +++ b/plugins/archlinux/archlinux.plugin.zsh @@ -9,7 +9,7 @@ else alias yaconf='yaourt -C' alias yaupg='yaourt -Syua' - alias yasu='yaourt --Syua --no-confirm' + alias yasu='yaourt -Syua --noconfirm' alias yain='yaourt -S' alias yains='yaourt -U' alias yare='yaourt -R' diff --git a/plugins/brew/_brew b/plugins/brew/_brew index 1f24bd67b..19cfb22cb 100644 --- a/plugins/brew/_brew +++ b/plugins/brew/_brew @@ -33,6 +33,10 @@ _brew_outdated_formulae() { outdated_formulae=(`brew outdated`) } +_brew_installed_services() { + installed_services=(`brew services list | awk '{print $1}' | tail -n+2`) +} + local -a _1st_arguments _1st_arguments=( 'audit:check formulae for Homebrew coding style' @@ -64,6 +68,7 @@ _1st_arguments=( 'prune:remove dead links' 'remove:remove a formula' 'search:search for a formula (/regex/ or string)' + 'services:manage services' 'switch:switch between different versions of a formula' 'tap:tap a new formula repository from GitHub, or list existing taps' 'tap-info:information about a tap' @@ -82,7 +87,7 @@ _1st_arguments=( ) local expl -local -a formulae installed_formulae installed_taps official_taps outdated_formulae +local -a formulae installed_formulae installed_taps official_taps outdated_formulae installed_services _arguments \ '(-v)-v[verbose]' \ @@ -142,4 +147,28 @@ case "$words[1]" in upgrade) _brew_outdated_formulae _wanted outdated_formulae expl 'outdated formulae' compadd -a outdated_formulae ;; + services) + _arguments -C \ + '1: :->command' \ + '2: :->service' && return 0 + + local -a commands + + commands=( + 'cleanup:Get rid of stale services and unused plists' + 'list:List all services managed by brew services' + 'restart:Gracefully restart selected service' + 'start:Start selected service' + 'stop:Stop selected service' + ) + + case $state in + command) + _describe -t commands 'Action' commands + ;; + service) + _brew_installed_services + _describe -t subcommands 'Services' installed_services + ;; + esac esac diff --git a/plugins/coffee/README.md b/plugins/coffee/README.md index 432ce3414..d6cd074d3 100644 --- a/plugins/coffee/README.md +++ b/plugins/coffee/README.md @@ -1,7 +1,7 @@ ## Coffeescript Plugin This plugin provides aliases for quickly compiling and previewing your -cofeescript code. +coffeescript code. When writing Coffeescript it's very common to want to preview the output of a certain snippet of code, either because you want to test the output or because diff --git a/plugins/docker-compose/docker-compose.plugin.zsh b/plugins/docker-compose/docker-compose.plugin.zsh new file mode 100644 index 000000000..351e77824 --- /dev/null +++ b/plugins/docker-compose/docker-compose.plugin.zsh @@ -0,0 +1,13 @@ +# Authors: +# https://github.com/tristola +# +# Docker-compose related zsh aliases + +# Aliases ################################################################### + +alias dcup='docker-compose up' +alias dcb='docker-compose build' +alias dcrm='docker-compose rm' +alias dcps='docker-compose ps' +alias dcstop='docker-compose stop' +alias dcrestart='docker-compose restart' diff --git a/plugins/droplr/README.md b/plugins/droplr/README.md new file mode 100644 index 000000000..cfbec25ed --- /dev/null +++ b/plugins/droplr/README.md @@ -0,0 +1,19 @@ +# droplr + +Use [Droplr](https://droplr.com/) from the comand line to upload files and shorten +links. It needs to have [Droplr.app](https://droplr.com/apps) installed and logged +in. MacOS only. + +To use it, add `droplr` to the `$plugins` variable in your zshrc file: + +```zsh +plugins=(... droplr) +``` + +Author: [Fabio Fernandes](https://github.com/fabiofl) + +## Examples + +- Upload a file: `droplr ./path/to/file/` + +- Shorten a link: `droplr http://example.com` diff --git a/plugins/droplr/droplr.plugin.zsh b/plugins/droplr/droplr.plugin.zsh new file mode 100644 index 000000000..296a8b98b --- /dev/null +++ b/plugins/droplr/droplr.plugin.zsh @@ -0,0 +1,15 @@ +# Only compatible with MacOS +[[ "$OSTYPE" == darwin* ]] || return + +droplr() { + if [[ $# -eq 0 ]]; then + echo You need to specify a parameter. >&2 + return 1 + fi + + if [[ "$1" =~ ^http[|s]:// ]]; then + osascript -e "tell app 'Droplr' to shorten '$1'" + else + open -ga /Applications/Droplr.app "$1" + fi +} diff --git a/plugins/firewalld/firewalld.plugin.zsh b/plugins/firewalld/firewalld.plugin.zsh new file mode 100644 index 000000000..bfbf6f48f --- /dev/null +++ b/plugins/firewalld/firewalld.plugin.zsh @@ -0,0 +1,17 @@ +alias fw="sudo firewall-cmd" +alias fwp="sudo firewall-cmd --permanent" +alias fwr="sudo firewall-cmd --reload" +alias fwrp="sudo firewall-cmd --runtime-to-permanent" + +function fwl () { + # converts output to zsh array () + # @f flag split on new line + zones=("${(@f)$(sudo firewall-cmd --get-active-zones | grep -v interfaces)}") + + for i in $zones; do + sudo firewall-cmd --zone $i --list-all + done + + echo 'Direct Rules:' + sudo firewall-cmd --direct --get-all-rules +} diff --git a/plugins/firewalld/readme.md b/plugins/firewalld/readme.md new file mode 100644 index 000000000..8b5bc74d4 --- /dev/null +++ b/plugins/firewalld/readme.md @@ -0,0 +1,22 @@ +# FirewallD Plugin + +This plugin adds some aliases and functions for FirewallD using the `firewalld-cmd` command. To use it, add firewalld to your plugins array. + +```zsh +plugins=(... firewalld) +``` + +## Aliases + +| Alias | Command | Description | +| :---- | :----------------------------------------- | :--------------------------- | +| fw | `sudo firewall-cmd` | Shorthand | +| fwr | `sudo firewall-cmd --reload` | Reload current configuration | +| fwp | `sudo firewall-cmd --permanent` | Create permanent rule | +| fwrp | `sudo firewall-cmd --runtime-to-permanent` | Save current configuration | + +## Functions + +| Function | Description | +| :------- | :--------------------------------------------------------- | +| fwl | Lists configuration from all active zones and direct rules | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index ef7cb94b0..6197c234b 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -161,7 +161,7 @@ compdef git-svn-dcommit-push=git alias gk='\gitk --all --branches' compdef _git gk='gitk' -alias gke='\gitk --all $(git log -g --pretty=format:%h)' +alias gke='\gitk --all $(git log -g --pretty=%h)' compdef _git gke='gitk' alias gl='git pull' @@ -171,8 +171,8 @@ alias glgg='git log --graph' alias glgga='git log --graph --decorate --all' alias glgm='git log --graph --max-count=10' alias glo='git log --oneline --decorate' -alias glol="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" -alias glola="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all" +alias glol="git log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" +alias glola="git log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all" alias glog='git log --oneline --decorate --graph' alias gloga='git log --oneline --decorate --graph --all' alias glp="_git_log_prettily" diff --git a/plugins/lein/lein.plugin.zsh b/plugins/lein/lein.plugin.zsh index 11c92979b..f4e50b447 100644 --- a/plugins/lein/lein.plugin.zsh +++ b/plugins/lein/lein.plugin.zsh @@ -33,6 +33,8 @@ function _lein_commands() { "version:print leiningen's version" ) _describe -t subcommands 'leiningen subcommands' subcommands && ret=0 + ;; + *) _files esac return ret diff --git a/plugins/npm/npm.plugin.zsh b/plugins/npm/npm.plugin.zsh index 30b91ec9c..02e4f3e93 100644 --- a/plugins/npm/npm.plugin.zsh +++ b/plugins/npm/npm.plugin.zsh @@ -2,10 +2,13 @@ __NPM_COMPLETION_FILE="${ZSH_CACHE_DIR}/npm_completion" if [[ ! -f $__NPM_COMPLETION_FILE ]]; then - npm completion >! $__NPM_COMPLETION_FILE || rm -f $__NPM_COMPLETION_FILE + npm completion >! $__NPM_COMPLETION_FILE 2>/dev/null + [[ $? -ne 0 ]] && rm -f $__NPM_COMPLETION_FILE fi - source $__NPM_COMPLETION_FILE + [[ -f $__NPM_COMPLETION_FILE ]] && source $__NPM_COMPLETION_FILE + + unset __NPM_COMPLETION_FILE } # Install dependencies globally diff --git a/plugins/ssh-agent/README.md b/plugins/ssh-agent/README.md new file mode 100644 index 000000000..00af42f01 --- /dev/null +++ b/plugins/ssh-agent/README.md @@ -0,0 +1,38 @@ +# ssh-agent plugin + +This plugin starts automatically `ssh-agent` to set up and load whichever +credentials you want for ssh connections. + +To enable it, add `ssh-agent` to your plugins: + +```zsh +plugins=(... ssh-agent) +``` + +## Instructions + +To enable **agent forwarding support** add the following to your zshrc file: + +```zsh +zstyle :omz:plugins:ssh-agent agent-forwarding on +``` + +To **load multiple identities** use the `identities` style, For example: + +```zsh +zstyle :omz:plugins:ssh-agent identities id_rsa id_rsa2 id_github +``` + +To **set the maximum lifetime of the identities**, use the `lifetime` style. +The lifetime may be specified in seconds or as described in sshd_config(5) +(see _TIME FORMATS_). If left unspecified, the default lifetime is forever. + +```zsh +zstyle :omz:plugins:ssh-agent lifetime 4h +``` + +## Credits + +Based on code from Joseph M. Reagle: http://www.cygwin.com/ml/cygwin/2001-06/msg00537.html + +Agent-forwarding support based on ideas from Florent Thoumie and Jonas Pfenniger diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh index b77b9ee78..b668fa3b2 100644 --- a/plugins/ssh-agent/ssh-agent.plugin.zsh +++ b/plugins/ssh-agent/ssh-agent.plugin.zsh @@ -1,79 +1,42 @@ -# -# INSTRUCTIONS -# -# To enable agent forwarding support add the following to -# your .zshrc file: -# -# zstyle :omz:plugins:ssh-agent agent-forwarding on -# -# To load multiple identities use the identities style, For -# example: -# -# zstyle :omz:plugins:ssh-agent identities id_rsa id_rsa2 id_github -# -# To set the maximum lifetime of the identities, use the -# lifetime style. The lifetime may be specified in seconds -# or as described in sshd_config(5) (see TIME FORMATS) -# If left unspecified, the default lifetime is forever. -# -# zstyle :omz:plugins:ssh-agent lifetime 4h -# -# CREDITS -# -# Based on code from Joseph M. Reagle -# http://www.cygwin.com/ml/cygwin/2001-06/msg00537.html -# -# Agent forwarding support based on ideas from -# Florent Thoumie and Jonas Pfenniger -# +typeset _agent_forwarding _ssh_env_cache -local _plugin__ssh_env -local _plugin__forwarding +function _start_agent() { + local lifetime + local -a identities -function _plugin__start_agent() -{ - local -a identities - local lifetime - zstyle -s :omz:plugins:ssh-agent lifetime lifetime + # start ssh-agent and setup environment + zstyle -s :omz:plugins:ssh-agent lifetime lifetime - # start ssh-agent and setup environment - /usr/bin/env ssh-agent ${lifetime:+-t} ${lifetime} | sed 's/^echo/#echo/' >! ${_plugin__ssh_env} - chmod 600 ${_plugin__ssh_env} - . ${_plugin__ssh_env} > /dev/null + ssh-agent -s ${lifetime:+-t} ${lifetime} | sed 's/^echo/#echo/' >! $_ssh_env_cache + chmod 600 $_ssh_env_cache + . $_ssh_env_cache > /dev/null - # load identies - zstyle -a :omz:plugins:ssh-agent identities identities - echo starting ssh-agent... + # load identies + zstyle -a :omz:plugins:ssh-agent identities identities - /usr/bin/ssh-add $HOME/.ssh/${^identities} + echo starting ssh-agent... + ssh-add $HOME/.ssh/${^identities} } # Get the filename to store/lookup the environment from -if (( $+commands[scutil] )); then - # It's OS X! - _plugin__ssh_env="$HOME/.ssh/environment-$(scutil --get ComputerName)" -else - _plugin__ssh_env="$HOME/.ssh/environment-$HOST" -fi +_ssh_env_cache="$HOME/.ssh/environment-$SHORT_HOST" # test if agent-forwarding is enabled -zstyle -b :omz:plugins:ssh-agent agent-forwarding _plugin__forwarding -if [[ ${_plugin__forwarding} == "yes" && -n "$SSH_AUTH_SOCK" ]]; then - # Add a nifty symlink for screen/tmux if agent forwarding - [[ -L $SSH_AUTH_SOCK ]] || ln -sf "$SSH_AUTH_SOCK" /tmp/ssh-agent-$USER-screen - -elif [ -f "${_plugin__ssh_env}" ]; then - # Source SSH settings, if applicable - . ${_plugin__ssh_env} > /dev/null - ps x | grep ${SSH_AGENT_PID} | grep ssh-agent > /dev/null || { - _plugin__start_agent; - } +zstyle -b :omz:plugins:ssh-agent agent-forwarding _agent_forwarding + +if [[ $_agent_forwarding == "yes" && -n "$SSH_AUTH_SOCK" ]]; then + # Add a nifty symlink for screen/tmux if agent forwarding + [[ -L $SSH_AUTH_SOCK ]] || ln -sf "$SSH_AUTH_SOCK" /tmp/ssh-agent-$USER-screen +elif [[ -f "$_ssh_env_cache" ]]; then + # Source SSH settings, if applicable + . $_ssh_env_cache > /dev/null + pgrep ssh-agent | grep -q $SSH_AGENT_PID || { + _start_agent + } else - _plugin__start_agent; + _start_agent fi # tidy up after ourselves -unfunction _plugin__start_agent -unset _plugin__forwarding -unset _plugin__ssh_env - +unset _agent_forwarding _ssh_env_cache +unfunction _start_agent diff --git a/plugins/vi-mode/vi-mode.plugin.zsh b/plugins/vi-mode/vi-mode.plugin.zsh index 0e2af5dce..82a2f3040 100644 --- a/plugins/vi-mode/vi-mode.plugin.zsh +++ b/plugins/vi-mode/vi-mode.plugin.zsh @@ -6,7 +6,7 @@ function zle-keymap-select() { # Ensure that the prompt is redrawn when the terminal size changes. TRAPWINCH() { - zle && { zle reset-prompt; zle -R } + zle && zle -R } zle -N zle-keymap-select @@ -28,6 +28,13 @@ 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%}" |