diff options
44 files changed, 750 insertions, 583 deletions
diff --git a/lib/clipboard.zsh b/lib/clipboard.zsh index 5bba11d16..808f2ea2d 100644 --- a/lib/clipboard.zsh +++ b/lib/clipboard.zsh @@ -3,10 +3,23 @@ # This file has support for doing system clipboard copy and paste operations # from the command line in a generic cross-platform fashion. # -# On OS X and Windows, the main system clipboard or "pasteboard" is used. On other -# Unix-like OSes, this considers the X Windows CLIPBOARD selection to be the -# "system clipboard", and the X Windows `xclip` command must be installed. - +# This is uses essentially the same heuristic as neovim, with the additional +# special support for Cygwin. +# See: https://github.com/neovim/neovim/blob/e682d799fa3cf2e80a02d00c6ea874599d58f0e7/runtime/autoload/provider/clipboard.vim#L55-L121 +# +# - pbcopy, pbpaste (macOS) +# - cygwin (Windows running Cygwin) +# - wl-copy, wl-paste (if $WAYLAND_DISPLAY is set) +# - xclip (if $DISPLAY is set) +# - xsel (if $DISPLAY is set) +# - lemonade (for SSH) https://github.com/pocke/lemonade +# - doitclient (for SSH) http://www.chiark.greenend.org.uk/~sgtatham/doit/ +# - win32yank (Windows) +# - tmux (if $TMUX is set) +# +# Defines two functions, clipcopy and clippaste, based on the detected platform. +## +# # clipcopy - Copy data to clipboard # # Usage: @@ -15,41 +28,8 @@ # # clipcopy <file> - copies a file's contents to clipboard # -function clipcopy() { - emulate -L zsh - local file=$1 - if [[ $OSTYPE == darwin* ]]; then - if [[ -z $file ]]; then - pbcopy - else - cat $file | pbcopy - fi - elif [[ $OSTYPE == (cygwin|msys)* ]]; then - if [[ -z $file ]]; then - cat > /dev/clipboard - else - cat $file > /dev/clipboard - fi - else - if (( $+commands[xclip] )); then - if [[ -z $file ]]; then - xclip -in -selection clipboard - else - xclip -in -selection clipboard $file - fi - elif (( $+commands[xsel] )); then - if [[ -z $file ]]; then - xsel --clipboard --input - else - cat "$file" | xsel --clipboard --input - fi - else - print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2 - return 1 - fi - fi -} - +## +# # clippaste - "Paste" data from clipboard to stdout # # Usage: @@ -67,20 +47,61 @@ function clipcopy() { # # # Paste to a file # clippaste > file.txt -function clippaste() { +# +function detect-clipboard() { emulate -L zsh - if [[ $OSTYPE == darwin* ]]; then - pbpaste - elif [[ $OSTYPE == (cygwin|msys)* ]]; then - cat /dev/clipboard + + if [[ "${OSTYPE}" == darwin* ]] && (( ${+commands[pbcopy]} )) && (( ${+commands[pbpaste]} )); then + function clipcopy() { pbcopy < "${1:-/dev/stdin}"; } + function clippaste() { pbpaste; } + elif [[ "${OSTYPE}" == (cygwin|msys)* ]]; then + function clipcopy() { cat "${1:-/dev/stdin}" > /dev/clipboard; } + function clippaste() { cat /dev/clipboard; } + elif [ -n "${WAYLAND_DISPLAY:-}" ] && (( ${+commands[wl-copy]} )) && (( ${+commands[wl-paste]} )); then + function clipcopy() { wl-copy < "${1:-/dev/stdin}"; } + function clippaste() { wl-paste; } + elif [ -n "${DISPLAY:-}" ] && (( ${+commands[xclip]} )); then + function clipcopy() { xclip -in -selection clipboard < "${1:-/dev/stdin}"; } + function clippaste() { xclip -out -selection clipboard; } + elif [ -n "${DISPLAY:-}" ] && (( ${+commands[xsel]} )); then + function clipcopy() { xsel --clipboard --input < "${1:-/dev/stdin}"; } + function clippaste() { xsel --clipboard --output; } + elif (( ${+commands[lemonade]} )); then + function clipcopy() { lemonade copy < "${1:-/dev/stdin}"; } + function clippaste() { lemonade paste; } + elif (( ${+commands[doitclient]} )); then + function clipcopy() { doitclient wclip < "${1:-/dev/stdin}"; } + function clippaste() { doitclient wclip -r; } + elif (( ${+commands[win32yank]} )); then + function clipcopy() { win32yank -i < "${1:-/dev/stdin}"; } + function clippaste() { win32yank -o; } + elif [[ $OSTYPE == linux-android* ]] && (( $+commands[termux-clipboard-set] )); then + function clipcopy() { termux-clipboard-set "${1:-/dev/stdin}"; } + function clippaste() { termux-clipboard-get; } + elif [ -n "${TMUX:-}" ] && (( ${+commands[tmux]} )); then + function clipcopy() { tmux load-buffer "${1:--}"; } + function clippaste() { tmux save-buffer -; } + elif [[ $(uname -r) = *icrosoft* ]]; then + function clipcopy() { clip.exe < "${1:-/dev/stdin}"; } + function clippaste() { _retry_clipboard_detection_or_fail clippaste "$@"; } else - if (( $+commands[xclip] )); then - xclip -out -selection clipboard - elif (( $+commands[xsel] )); then - xsel --clipboard --output - else - print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2 - return 1 - fi + function _retry_clipboard_detection_or_fail() { + local clipcmd="${1}"; shift + if detect-clipboard; then + "${clipcmd}" "$@" + else + print "${clipcmd}: Platform $OSTYPE not supported or xclip/xsel not installed" >&2 + return 1 + fi + } + function clipcopy() { _retry_clipboard_detection_or_fail clipcopy "$@"; } + function clippaste() { _retry_clipboard_detection_or_fail clippaste "$@"; } + return 1 fi } + +# Detect at startup. A non-zero exit here indicates that the dummy clipboards were set, +# which is not really an error. If the user calls them, they will attempt to redetect +# (for example, perhaps the user has now installed xclip) and then either print an error +# or proceed successfully. +detect-clipboard || true diff --git a/lib/functions.zsh b/lib/functions.zsh index 61dfa4780..91e9cf895 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -3,11 +3,12 @@ function zsh_stats() { } function uninstall_oh_my_zsh() { - env ZSH=$ZSH sh $ZSH/tools/uninstall.sh + env ZSH="$ZSH" sh "$ZSH/tools/uninstall.sh" } function upgrade_oh_my_zsh() { - env ZSH=$ZSH sh $ZSH/tools/upgrade.sh + env ZSH="$ZSH" sh "$ZSH/tools/upgrade.sh" + rm -rf "$ZSH/log/update.lock" } function take() { diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index c3fae6efb..30259372c 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -97,25 +97,12 @@ done unset config_file # Load the theme -if [[ "$ZSH_THEME" == "random" ]]; then - if [[ "${(t)ZSH_THEME_RANDOM_CANDIDATES}" = "array" ]] && [[ "${#ZSH_THEME_RANDOM_CANDIDATES[@]}" -gt 0 ]]; then - themes=($ZSH/themes/${^ZSH_THEME_RANDOM_CANDIDATES}.zsh-theme) +if [ ! "$ZSH_THEME" = "" ]; then + if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then + source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" + elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then + source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" else - themes=($ZSH/themes/*zsh-theme) - fi - N=${#themes[@]} - ((N=(RANDOM%N)+1)) - RANDOM_THEME=${themes[$N]} - source "$RANDOM_THEME" - echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..." -else - if [ ! "$ZSH_THEME" = "" ]; then - if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then - source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" - elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then - source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" - else - source "$ZSH/themes/$ZSH_THEME.zsh-theme" - fi + source "$ZSH/themes/$ZSH_THEME.zsh-theme" fi fi diff --git a/plugins/arcanist/README.md b/plugins/arcanist/README.md index f2ca8cf55..9c15f09b5 100644 --- a/plugins/arcanist/README.md +++ b/plugins/arcanist/README.md @@ -1,5 +1,29 @@ ## arcanist -**Maintainer:** [@emzar](https://github.com/emzar) - This plugin adds many useful aliases for [arcanist](https://github.com/phacility/arcanist). + +To use it, add `arcanist` to the plugins array of your zshrc file: + +```zsh +plugins=(... arcanist) +``` + +## Aliases + +| Alias | Command | +|---------|------------------------------------| +| ara | `arc amend` | +| arb | `arc branch` | +| arco | `arc cover` | +| arci | `arc commit` | +| ard | `arc diff` | +| ardc | `arc diff --create` | +| ardnu | `arc diff --nounit` | +| ardnupc | `arc diff --nounit --plan-changes` | +| ardpc | `arc diff --plan-changes` | +| are | `arc export` | +| arh | `arc help` | +| arl | `arc land` | +| arli | `arc lint` | +| arls | `arc list` | +| arpa | `arc patch` | diff --git a/plugins/arcanist/arcanist.plugin.zsh b/plugins/arcanist/arcanist.plugin.zsh index 3f4eb07f4..8918bffdd 100644 --- a/plugins/arcanist/arcanist.plugin.zsh +++ b/plugins/arcanist/arcanist.plugin.zsh @@ -9,6 +9,7 @@ alias arco='arc cover' alias arci='arc commit' alias ard='arc diff' +alias ardc='arc diff --create' alias ardnu='arc diff --nounit' alias ardnupc='arc diff --nounit --plan-changes' alias ardpc='arc diff --plan-changes' diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index 6fe801c9f..4c4d0d4fc 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -18,10 +18,10 @@ if [[ "$OSTYPE" = darwin* ]]; then } function battery_pct() { - local smart_battery_status="$(ioreg -rc AppleSmartBattery)" - local -F maxcapacity=$(command grep '^.*"MaxCapacity"\ =\ ' <<< $smart_battery_status | sed -e 's/^.*"MaxCapacity"\ =\ //') - local -F currentcapacity=$(command grep '^.*"CurrentCapacity"\ =\ ' <<< $smart_battery_status | sed -e 's/^.*CurrentCapacity"\ =\ //') - echo $(( (currentcapacity/maxcapacity) * 100 )) + local battery_status="$(ioreg -rc AppleSmartBattery)" + local -i capacity=$(sed -n -e '/MaxCapacity/s/^.*"MaxCapacity"\ =\ //p' <<< $battery_status) + local -i current=$(sed -n -e '/CurrentCapacity/s/^.*"CurrentCapacity"\ =\ //p' <<< $battery_status) + echo $(( current * 100 / capacity )) } function battery_pct_remaining() { @@ -47,16 +47,17 @@ if [[ "$OSTYPE" = darwin* ]]; then } function battery_pct_prompt () { + local battery_pct color if ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ No'; then - b=$(battery_pct_remaining) - if [[ $b -gt 50 ]]; then + battery_pct=$(battery_pct_remaining) + if [[ $battery_pct -gt 50 ]]; then color='green' - elif [[ $b -gt 20 ]]; then + elif [[ $battery_pct -gt 20 ]]; then color='yellow' else color='red' fi - echo "%{$fg[$color]%}[$(battery_pct_remaining)%%]%{$reset_color%}" + echo "%{$fg[$color]%}[${battery_pct}%%]%{$reset_color%}" else echo "∞" fi @@ -93,19 +94,19 @@ elif [[ "$OSTYPE" = freebsd* ]]; then } function battery_pct_prompt() { - local b color - b=$(battery_pct_remaining) + local battery_pct color + battery_pct=$(battery_pct_remaining) if battery_is_charging; then echo "∞" else - if [[ $b -gt 50 ]]; then + if [[ $battery_pct -gt 50 ]]; then color='green' - elif [[ $b -gt 20 ]]; then + elif [[ $battery_pct -gt 20 ]]; then color='yellow' else color='red' fi - echo "%{$fg[$color]%}$(battery_pct_remaining)%%%{$reset_color%}" + echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}" fi } @@ -136,19 +137,19 @@ elif [[ "$OSTYPE" = linux* ]]; then } function battery_pct_prompt() { - local b color - b=$(battery_pct_remaining) + local battery_pct color + battery_pct=$(battery_pct_remaining) if battery_is_charging; then echo "∞" else - if [[ $b -gt 50 ]]; then + if [[ $battery_pct -gt 50 ]]; then color='green' - elif [[ $b -gt 20 ]]; then + elif [[ $battery_pct -gt 20 ]]; then color='yellow' else color='red' fi - echo "%{$fg[$color]%}$(battery_pct_remaining)%%%{$reset_color%}" + echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}" fi } diff --git a/plugins/cloudapp/README.md b/plugins/cloudapp/README.md index 62975a631..6c7f9bc6c 100644 --- a/plugins/cloudapp/README.md +++ b/plugins/cloudapp/README.md @@ -5,7 +5,7 @@ To use it, add `cloudapp` to the plugins array of your `~/.zshrc` file: ``` -plugins=(... dash) +plugins=(... cloudapp) ``` ## Requirements diff --git a/plugins/copybuffer/copybuffer.plugin.zsh b/plugins/copybuffer/copybuffer.plugin.zsh index cc205d40f..483ed5a5f 100644 --- a/plugins/copybuffer/copybuffer.plugin.zsh +++ b/plugins/copybuffer/copybuffer.plugin.zsh @@ -1,9 +1,9 @@ # copy the active line from the command line buffer -# onto the system clipboard (requires clipcopy plugin) +# onto the system clipboard copybuffer () { if which clipcopy &>/dev/null; then - echo $BUFFER | clipcopy + printf "%s" "$BUFFER" | clipcopy else echo "clipcopy function not found. Please make sure you have Oh My Zsh installed correctly." fi diff --git a/plugins/dotenv/README.md b/plugins/dotenv/README.md index cac552485..dbc02bf61 100644 --- a/plugins/dotenv/README.md +++ b/plugins/dotenv/README.md @@ -32,6 +32,8 @@ PORT=3001 ``` You can even mix both formats, although it's probably a bad idea. +## Plugin options + ### ZSH_DOTENV_FILE You can also modify the name of the file to be loaded with the variable `ZSH_DOTENV_FILE`. @@ -43,6 +45,10 @@ For example, this will make the plugin look for files named `.dotenv` and load t ZSH_DOTENV_FILE=.dotenv ``` +### ZSH_DOTENV_PROMPT + +Set `ZSH_DOTENV_PROMPT=false` in your zshrc file if you don't want the confirmation message. + ## Version Control **It's strongly recommended to add `.env` file to `.gitignore`**, because usually it contains sensitive information such as your credentials, secret keys, passwords etc. You don't want to commit this file, it's supposed to be local only. diff --git a/plugins/dotenv/dotenv.plugin.zsh b/plugins/dotenv/dotenv.plugin.zsh index d4a6db8f8..54036bee3 100644 --- a/plugins/dotenv/dotenv.plugin.zsh +++ b/plugins/dotenv/dotenv.plugin.zsh @@ -1,10 +1,15 @@ source_env() { if [[ -f $ZSH_DOTENV_FILE ]]; then - # confirm before sourcing .env file - local confirmation - echo -n "dotenv: source '$ZSH_DOTENV_FILE' file in the directory? (Y/n) " - if read -k 1 confirmation && [[ $confirmation = [nN] ]]; then - return + if [ "$ZSH_DOTENV_PROMPT" != "false" ]; then + # confirm before sourcing file + local confirmation + # print same-line prompt and output newline character if necessary + echo -n "dotenv: source '$ZSH_DOTENV_FILE' file in the directory? (Y/n) " + read -k 1 confirmation; [[ "$confirmation" != $'\n' ]] && echo + # only bail out if confirmation character is n + if [[ "$confirmation" = [nN] ]]; then + return + fi fi # test .env syntax diff --git a/plugins/dotnet/README.md b/plugins/dotnet/README.md index a663fc88d..7554b4e3c 100644 --- a/plugins/dotnet/README.md +++ b/plugins/dotnet/README.md @@ -20,4 +20,4 @@ plugins=(... dotnet) | ds | dotnet sln | Modify Visual Studio solution files. | | da | dotnet add | Add a package or reference to a .NET project. | | dp | dotnet pack | Create a NuGet package. | -| dng | dotnet nuget | Provides additional NuGet commands. |
\ No newline at end of file +| dng | dotnet nuget | Provides additional NuGet commands. | diff --git a/plugins/dotnet/dotnet.plugin.zsh b/plugins/dotnet/dotnet.plugin.zsh index ed6c68e5d..6bd4b7af8 100644 --- a/plugins/dotnet/dotnet.plugin.zsh +++ b/plugins/dotnet/dotnet.plugin.zsh @@ -1,114 +1,27 @@ -# --------------------------------------------------------------------- # -# Aliases and Completions for .NET Core (https://dotnet.microsoft.com/) # -# Author: Shaun Tabone (https://github.com/xontab) # -# --------------------------------------------------------------------- # +# This scripts is copied from (MIT License): +# https://github.com/dotnet/toolset/blob/master/scripts/register-completions.zsh -# Helper function to cache and load completions -local cache_base_path="${ZSH_CACHE_DIR}/dotnet_" -_dotnet_cache_completion() { - local cache="${cache_base_path}$(echo $1)_completion" - if [[ ! -f $cache ]]; then - $2 $cache - fi +_dotnet_zsh_complete() +{ + local completions=("$(dotnet complete "$words")") - [[ -f $cache ]] && cat $cache -} + # If the completion list is empty, just continue with filename selection + if [ -z "$completions" ] + then + _arguments '*::arguments: _normal' + return + fi -_dotnet_cache_completion_cleanup() { - local cache="${cache_base_path}$(echo $1)_completion" - rm -f $cache + # This is not a variable assigment, don't remove spaces! + _values = "${(ps:\n:)completions}" } -# --------------------------------------------------------------------- # -# dotnet new # -# ALIAS: dn # -# --------------------------------------------------------------------- # -_dotnet_new_completion() { - if [ $commands[dotnet] ]; then - dotnet new -l | tail -n +21 | sed 's/ \+/:/g' | cut -d : -f 2 >$1 - fi -} +compdef _dotnet_zsh_complete dotnet -_dotnet_new_completion_cached() { - _dotnet_cache_completion 'new' _dotnet_new_completion -} - -_dotnet_cache_completion_cleanup 'new' +# Aliases bellow are here for backwards compatibility +# added by Shaun Tabone (https://github.com/xontab) alias dn='dotnet new' - -# --------------------------------------------------------------------- # -# dotnet # -# --------------------------------------------------------------------- # -_dotnet() { - if [ $CURRENT -eq 2 ]; then - _arguments \ - '--diagnostics[Enable diagnostic output.]' \ - '--help[Show command line help.]' \ - '--info[Display .NET Core information.]' \ - '--list-runtimes[Display the installed runtimes.]' \ - '--list-sdks[Display the installed SDKs.]' \ - '--version[Display .NET Core SDK version in use.]' - - _values \ - 'add[Add a package or reference to a .NET project.]' \ - 'build[Build a .NET project.]' \ - 'build-server[Interact with servers started by a build.]' \ - 'clean[Clean build outputs of a .NET project.]' \ - 'help[Show command line help.]' \ - 'list[List project references of a .NET project.]' \ - 'msbuild[Run Microsoft Build Engine (MSBuild) commands.]' \ - 'new[Create a new .NET project or file.]' \ - 'nuget[Provides additional NuGet commands.]' \ - 'pack[Create a NuGet package.]' \ - 'publish[Publish a .NET project for deployment.]' \ - 'remove[Remove a package or reference from a .NET project.]' \ - 'restore[Restore dependencies specified in a .NET project.]' \ - 'run[Build and run a .NET project output.]' \ - 'sln[Modify Visual Studio solution files.]' \ - 'store[Store the specified assemblies in the runtime package store.]' \ - 'test[Run unit tests using the test runner specified in a .NET project.]' \ - 'tool[Install or manage tools that extend the .NET experience.]' \ - 'vstest[Run Microsoft Test Engine (VSTest) commands.]' \ - 'dev-certs[Create and manage development certificates.]' \ - 'fsi[Start F# Interactive / execute F# scripts.]' \ - 'sql-cache[SQL Server cache command-line tools.]' \ - 'user-secrets[Manage development user secrets.]' \ - 'watch[Start a file watcher that runs a command when files change.]' - return - fi - - if [ $CURRENT -eq 3 ]; then - case ${words[2]} in - "new") - compadd -X ".NET Installed Templates" $(_dotnet_new_completion_cached) - return - ;; - "sln") - _values \ - 'add[Add one or more projects to a solution file.]' \ - 'list[List all projects in a solution file.]' \ - 'remove[Remove one or more projects from a solution file.]' - return - ;; - "nuget") - _values \ - 'delete[Deletes a package from the server.]' \ - 'locals[Clears or lists local NuGet resources such as http requests cache, packages folder, plugin operations cache or machine-wide global packages folder.]' \ - 'push[Pushes a package to the server and publishes it.]' - return - ;; - esac - fi - - _arguments '*::arguments: _normal' -} - -compdef _dotnet dotnet - -# --------------------------------------------------------------------- # -# Other Aliases # -# --------------------------------------------------------------------- # alias dr='dotnet run' alias dt='dotnet test' alias dw='dotnet watch' diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh index c8aefd7ab..53bdcbc97 100644 --- a/plugins/fzf/fzf.plugin.zsh +++ b/plugins/fzf/fzf.plugin.zsh @@ -10,6 +10,7 @@ function setup_using_base_dir() { if [[ -z "${fzf_base}" ]]; then fzfdirs=( "${HOME}/.fzf" + "${HOME}/.nix-profile/share/fzf" "/usr/local/opt/fzf" "/usr/share/fzf" "/usr/local/share/examples/fzf" @@ -31,8 +32,8 @@ function setup_using_base_dir() { fi if [[ -d "${fzf_base}" ]]; then - # Fix fzf shell directory for Archlinux package - if [[ ! -d "${fzf_base}/shell" ]] && [[ -f /etc/arch-release ]]; then + # Fix fzf shell directory for Arch Linux, NixOS or Void Linux packages + if [[ ! -d "${fzf_base}/shell" ]]; then fzf_shell="${fzf_base}" else fzf_shell="${fzf_base}/shell" diff --git a/plugins/git/README.md b/plugins/git/README.md index 7878f747b..009a74016 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -10,194 +10,196 @@ plugins=(... git) ## Aliases -| Alias | Command | -|:---------------------|:------------------------------------------------------------------------------------------------------------------------------| -| g | git | -| ga | git add | -| gaa | git add --all | -| gapa | git add --patch | -| gau | git add --update | -| gav | git add --verbose | -| gap | git apply | -| gb | git branch | -| gba | git branch -a | -| gbd | git branch -d | +| Alias | Command | +|:---------------------|:---------------------------------------------------------------------------------------------------------------------------------| +| g | git | +| ga | git add | +| gaa | git add --all | +| gapa | git add --patch | +| gau | git add --update | +| gav | git add --verbose | +| gap | git apply | +| gb | git branch | +| gba | git branch -a | +| gbd | git branch -d | | gbda | git branch --no-color --merged \| command grep -vE "^(\+|\*\|\s*(master\|develop\|dev)\s*$)" \| command xargs -n 1 git branch -d | -| gbD | git branch -D | -| gbl | git blame -b -w | -| gbnm | git branch --no-merged | -| gbr | git branch --remote | -| gbs | git bisect | -| gbsb | git bisect bad | -| gbsg | git bisect good | -| gbsr | git bisect reset | -| gbss | git bisect start | -| gc | git commit -v | -| gc! | git commit -v --amend | -| gcn! | git commit -v --no-edit --amend | -| gca | git commit -v -a | -| gca! | git commit -v -a --amend | -| gcan! | git commit -v -a --no-edit --amend | -| gcans! | git commit -v -a -s --no-edit --amend | -| gcam | git commit -a -m | -| gcsm | git commit -s -m | -| gcb | git checkout -b | -| gcf | git config --list | -| gcl | git clone --recurse-submodules | -| gclean | git clean -id | -| gpristine | git reset --hard && git clean -dfx | -| gcm | git checkout master | -| gcd | git checkout develop | -| gcmsg | git commit -m | -| gco | git checkout | -| gcount | git shortlog -sn | -| gcp | git cherry-pick | -| gcpa | git cherry-pick --abort | -| gcpc | git cherry-pick --continue | -| gcs | git commit -S | -| gd | git diff | -| gdca | git diff --cached | -| gdcw | git diff --cached --word-diff | -| gdct | git describe --tags $(git rev-list --tags --max-count=1) | -| gds | git diff --staged | -| gdt | git diff-tree --no-commit-id --name-only -r | -| gdv | git diff -w $@ \| view - | -| gdw | git diff --word-diff | -| gf | git fetch | -| gfa | git fetch --all --prune | -| gfg | git ls-files \| grep | -| gfo | git fetch origin | -| gg | git gui citool | -| gga | git gui citool --amend | -| ggf | git push --force origin $(current_branch) | -| ggfl | git push --force-with-lease origin $(current_branch) | -| ggl | git pull origin $(current_branch) | -| ggp | git push origin $(current_branch) | -| ggpnp | ggl && ggp | -| ggpull | git pull origin "$(git_current_branch)" | -| ggpur | ggu | -| ggpush | git push origin "$(git_current_branch)" | -| ggsup | git branch --set-upstream-to=origin/$(git_current_branch) | -| ggu | git pull --rebase origin $(current_branch) | -| gpsup | git push --set-upstream origin $(git_current_branch) | -| ghh | git help | -| gignore | git update-index --assume-unchanged | -| gignored | git ls-files -v \| grep "^[[:lower:]]" | -| git-svn-dcommit-push | git svn dcommit && git push github master:svntrunk | -| gk | gitk --all --branches | -| gke | gitk --all $(git log -g --pretty=%h) | -| gl | git pull | -| glg | git log --stat | -| glgp | git log --stat -p | -| glgg | git log --graph | -| glgga | git log --graph --decorate --all | -| glgm | git log --graph --max-count=10 | -| glo | git log --oneline --decorate | -| glol | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' | -| glols | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --stat | -| glod | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' | -| glods | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short | -| glola | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all | -| glog | git log --oneline --decorate --graph | -| gloga | git log --oneline --decorate --graph --all | -| glp | `_git_log_prettily` | -| gm | git merge | -| gmom | git merge origin/master | -| gmt | git mergetool --no-prompt | -| gmtvim | git mergetool --no-prompt --tool=vimdiff | -| gmum | git merge upstream/master | -| gma | git merge --abort | -| gp | git push | -| gpd | git push --dry-run | -| gpf | git push --force-with-lease | -| gpf! | git push --force | -| gpoat | git push origin --all && git push origin --tags | -| gpu | git push upstream | -| gpv | git push -v | -| gr | git remote | -| gra | git remote add | -| grb | git rebase | -| grba | git rebase --abort | -| grbc | git rebase --continue | -| grbd | git rebase develop | -| grbi | git rebase -i | -| grbm | git rebase master | -| grbs | git rebase --skip | -| grev | git revert | -| grh | git reset | -| grhh | git reset --hard | -| groh | git reset origin/$(git_current_branch) --hard | -| grm | git rm | -| grmc | git rm --cached | -| grmv | git remote rename | -| grrm | git remote remove | -| grs | git restore | -| grset | git remote set-url | -| grss | git restore --source | -| grt | cd "$(git rev-parse --show-toplevel \|\| echo .)" | -| gru | git reset -- | -| grup | git remote update | -| grv | git remote -v | -| gsb | git status -sb | -| gsd | git svn dcommit | -| gsh | git show | -| gsi | git submodule init | -| gsps | git show --pretty=short --show-signature | -| gsr | git svn rebase | -| gss | git status -s | -| gst | git status | -| gsta | git stash push | -| gsta | git stash save | -| gstaa | git stash apply | -| gstc | git stash clear | -| gstd | git stash drop | -| gstl | git stash list | -| gstp | git stash pop | -| gsts | git stash show --text | -| gstall | git stash --all | -| gsu | git submodule update | -| gsw | git switch | -| gswc | git switch -c | -| gts | git tag -s | -| gtv | git tag \| sort -V | -| gtl | gtl(){ git tag --sort=-v:refname -n -l ${1}* }; noglob gtl | -| gunignore | git update-index --no-assume-unchanged | -| gunwip | git log -n 1 \| grep -q -c "\-\-wip\-\-" && git reset HEAD~1 | -| gup | git pull --rebase | -| gupv | git pull --rebase -v | -| gupa | git pull --rebase --autostash | -| gupav | git pull --rebase --autostash -v | -| glum | git pull upstream master | -| gwch | git whatchanged -p --abbrev-commit --pretty=medium | -| gwip | git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign -m "--wip-- [skip ci]" | +| gbD | git branch -D | +| gbl | git blame -b -w | +| gbnm | git branch --no-merged | +| gbr | git branch --remote | +| gbs | git bisect | +| gbsb | git bisect bad | +| gbsg | git bisect good | +| gbsr | git bisect reset | +| gbss | git bisect start | +| gc | git commit -v | +| gc! | git commit -v --amend | +| gcn! | git commit -v --no-edit --amend | +| gca | git commit -v -a | +| gca! | git commit -v -a --amend | +| gcan! | git commit -v -a --no-edit --amend | +| gcans! | git commit -v -a -s --no-edit --amend | +| gcam | git commit -a -m | +| gcsm | git commit -s -m | +| gcb | git checkout -b | +| gcf | git config --list | +| gcl | git clone --recurse-submodules | +| gclean | git clean -id | +| gpristine | git reset --hard && git clean -dfx | +| gcm | git checkout master | +| gcd | git checkout develop | +| gcmsg | git commit -m | +| gco | git checkout | +| gcount | git shortlog -sn | +| gcp | git cherry-pick | +| gcpa | git cherry-pick --abort | +| gcpc | git cherry-pick --continue | +| gcs | git commit -S | +| gd | git diff | +| gdca | git diff --cached | +| gdcw | git diff --cached --word-diff | +| gdct | git describe --tags $(git rev-list --tags --max-count=1) | +| gds | git diff --staged | +| gdt | git diff-tree --no-commit-id --name-only -r | +| gdv | git diff -w $@ \| view - | +| gdw | git diff --word-diff | +| gf | git fetch | +| gfa | git fetch --all --prune | +| gfg | git ls-files \| grep | +| gfo | git fetch origin | +| gg | git gui citool | +| gga | git gui citool --amend | +| ggf | git push --force origin $(current_branch) | +| ggfl | git push --force-with-lease origin $(current_branch) | +| ggl | git pull origin $(current_branch) | +| ggp | git push origin $(current_branch) | +| ggpnp | ggl && ggp | +| ggpull | git pull origin "$(git_current_branch)" | +| ggpur | ggu | +| ggpush | git push origin "$(git_current_branch)" | +| ggsup | git branch --set-upstream-to=origin/$(git_current_branch) | +| ggu | git pull --rebase origin $(current_branch) | +| gpsup | git push --set-upstream origin $(git_current_branch) | +| ghh | git help | +| gignore | git update-index --assume-unchanged | +| gignored | git ls-files -v \| grep "^[[:lower:]]" | +| git-svn-dcommit-push | git svn dcommit && git push github master:svntrunk | +| gk | gitk --all --branches | +| gke | gitk --all $(git log -g --pretty=%h) | +| gl | git pull | +| glg | git log --stat | +| glgp | git log --stat -p | +| glgg | git log --graph | +| glgga | git log --graph --decorate --all | +| glgm | git log --graph --max-count=10 | +| glo | git log --oneline --decorate | +| glol | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' | +| glols | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --stat | +| glod | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' | +| glods | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short | +| glola | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all | +| glog | git log --oneline --decorate --graph | +| gloga | git log --oneline --decorate --graph --all | +| glp | `_git_log_prettily` | +| gm | git merge | +| gmom | git merge origin/master | +| gmt | git mergetool --no-prompt | +| gmtvim | git mergetool --no-prompt --tool=vimdiff | +| gmum | git merge upstream/master | +| gma | git merge --abort | +| gp | git push | +| gpd | git push --dry-run | +| gpf | git push --force-with-lease | +| gpf! | git push --force | +| gpoat | git push origin --all && git push origin --tags | +| gpu | git push upstream | +| gpv | git push -v | +| gr | git remote | +| gra | git remote add | +| grb | git rebase | +| grba | git rebase --abort | +| grbc | git rebase --continue | +| grbd | git rebase develop | +| grbi | git rebase -i | +| grbm | git rebase master | +| grbs | git rebase --skip | +| grev | git revert | +| grh | git reset | +| grhh | git reset --hard | +| groh | git reset origin/$(git_current_branch) --hard | +| grm | git rm | +| grmc | git rm --cached | +| grmv | git remote rename | +| grrm | git remote remove | +| grs | git restore | +| grset | git remote set-url | +| grss | git restore --source | +| grt | cd "$(git rev-parse --show-toplevel \|\| echo .)" | +| gru | git reset -- | +| grup | git remote update | +| grv | git remote -v | +| gsb | git status -sb | +| gsd | git svn dcommit | +| gsh | git show | +| gsi | git submodule init | +| gsps | git show --pretty=short --show-signature | +| gsr | git svn rebase | +| gss | git status -s | +| gst | git status | +| gsta | git stash push | +| gsta | git stash save | +| gstaa | git stash apply | +| gstc | git stash clear | +| gstd | git stash drop | +| gstl | git stash list | +| gstp | git stash pop | +| gsts | git stash show --text | +| gstu | git stash --include-untracked | +| gstall | git stash --all | +| gsu | git submodule update | +| gsw | git switch | +| gswc | git switch -c | +| gts | git tag -s | +| gtv | git tag \| sort -V | +| gtl | gtl(){ git tag --sort=-v:refname -n -l ${1}* }; noglob gtl | +| gunignore | git update-index --no-assume-unchanged | +| gunwip | git log -n 1 \| grep -q -c "\-\-wip\-\-" && git reset HEAD~1 | +| gup | git pull --rebase | +| gupv | git pull --rebase -v | +| gupa | git pull --rebase --autostash | +| gupav | git pull --rebase --autostash -v | +| glum | git pull upstream master | +| gwch | git whatchanged -p --abbrev-commit --pretty=medium | +| gwip | git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign -m "--wip-- [skip ci]" | ### Deprecated These are aliases that have been removed, renamed, or otherwise modified in a way that may, or may not, receive further support. -| Alias | Command | Modification | -| :----- | :----------------------------------------------------------------------------------| --------------------------------------------------------------------------------------------------- | -| gap | git add --patch | new alias `gapa` | -| gcl | git config --list | new alias `gcf` | -| gdc | git diff --cached | new alias `gdca` | -| gdt | git difftool | no replacement | -| ggpull | git pull origin $(current_branch) | new alias `ggl` (`ggpull` still exists for now though) | -| ggpur | git pull --rebase origin $(current_branch) | new alias `ggu` (`ggpur` still exists for now though) | -| ggpush | git push origin $(current_branch) | new alias `ggp` (`ggpush` still exists for now though) | -| gk | gitk --all --branches | now aliased to `gitk --all --branches` | -| glg | git log --stat --max-count = 10 | now aliased to `git log --stat --color` | -| glgg | git log --graph --max-count = 10 | now aliased to `git log --graph --color` | -| gwc | git whatchanged -p --abbrev-commit --pretty = medium | new alias `gwch` | +| Alias | Command | Modification | +| :----- | :----------------------------------------------------- | :----------------------------------------------------- | +| gap | `git add --patch` | new alias `gapa` | +| gcl | `git config --list` | new alias `gcf` | +| gdc | `git diff --cached` | new alias `gdca` | +| gdt | `git difftool` | no replacement | +| ggpull | `git pull origin $(current_branch)` | new alias `ggl` (`ggpull` still exists for now though) | +| ggpur | `git pull --rebase origin $(current_branch)` | new alias `ggu` (`ggpur` still exists for now though) | +| ggpush | `git push origin $(current_branch)` | new alias `ggp` (`ggpush` still exists for now though) | +| gk | `gitk --all --branches` | now aliased to `gitk --all --branches` | +| glg | `git log --stat --max-count = 10` | now aliased to `git log --stat --color` | +| glgg | `git log --graph --max-count = 10` | now aliased to `git log --graph --color` | +| gwc | `git whatchanged -p --abbrev-commit --pretty = medium` | new alias `gwch` | ## Functions ### Current -| Command | Description | -|:-----------------------|:----------------------------------------| -| current_branch | Return the name of the current branch | -| git_current_user_name | Returns the `user.name` config value | -| git_current_user_email | Returns the `user.email` config value | +| Command | Description | +|:-----------------------|:---------------------------------------------------------| +| `grename <old> <new>` | Rename `old` branch to `new`, including in origin remote | +| current_branch | Return the name of the current branch | +| git_current_user_name | Returns the `user.name` config value | +| git_current_user_email | Returns the `user.email` config value | ### Work in Progress (WIP) diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index d8c4cffd1..ffb3e506a 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -236,6 +236,7 @@ alias gstd='git stash drop' alias gstl='git stash list' alias gstp='git stash pop' alias gsts='git stash show --text' +alias gstu='git stash --include-untracked' alias gstall='git stash --all' alias gsu='git submodule update' alias gsw='git switch' @@ -255,3 +256,17 @@ alias glum='git pull upstream master' alias gwch='git whatchanged -p --abbrev-commit --pretty=medium' alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign -m "--wip-- [skip ci]"' + +function grename() { + if [[ -z "$1" || -z "$2" ]]; then + echo "Usage: $0 old_branch new_branch" + return 1 + fi + + # Rename branch locally + git branch -m "$1" "$2" + # Rename branch in origin remote + if git push origin :"$1"; then + git push --set-upstream origin "$2" + fi +} diff --git a/plugins/jfrog/README.md b/plugins/jfrog/README.md new file mode 100644 index 000000000..1d858620b --- /dev/null +++ b/plugins/jfrog/README.md @@ -0,0 +1,11 @@ +# JFrog CLI + +This plugin provides completion for [JFrog CLI](https://github.com/jfrog/jfrog-cli). + +JFrog CLI provides a simple interface that automates access to [Artifactory](https://jfrog.com/artifactory), [Xray](https://jfrog.com/xray), [Bintray](https://jfrog.com/bintray) and [Mission Control](https://jfrog.com/mission-control) through their respective REST APIs. + +To use it, add `jfrog` to the plugins array in your zshrc file: + +```zsh +plugins=(... jfrog) +``` diff --git a/plugins/jfrog/jfrog.plugin.zsh b/plugins/jfrog/jfrog.plugin.zsh new file mode 100644 index 000000000..064ffa2db --- /dev/null +++ b/plugins/jfrog/jfrog.plugin.zsh @@ -0,0 +1,10 @@ +_jfrog() { + local -a opts + opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}") + _describe 'values' opts + if [[ $compstate[nmatches] -eq 0 && $words[$CURRENT] != -* ]]; then + _files + fi +} + +compdef _jfrog jfrog
\ No newline at end of file diff --git a/plugins/jhbuild/README.md b/plugins/jhbuild/README.md index 910526966..3220e0daf 100644 --- a/plugins/jhbuild/README.md +++ b/plugins/jhbuild/README.md @@ -1,4 +1,34 @@ -## JHBuild +# JHBuild + +This plugin adds some [JHBuild](https://developer.gnome.org/jhbuild/) aliases. + +To use it, add `jhbuild` to the plugins array of your zshrc file: + +```zsh +plugins=(... jhbuild) +``` + **Maintainer:** [Miguel Vaello](https://github.com/miguxbe) -This plugin adds some jhbuild aliases and increase the completion function provided by zsh. +## Aliases + +| Alias | Command | +|---------|---------------------------| +| `jh` | `jhbuild` | +| `jhb` | `jhbuild build` | +| `jhbo` | `jhbuild buildone` | +| `jhckb` | `jhbuild checkbranches` | +| `jhckm` | `jhbuild checkmodulesets` | +| `jhi` | `jhbuild info` | +| `jhl` | `jhbuild list` | +| `jhc` | `jhbuild clean` | +| `jhco` | `jhbuild cleanone` | +| `jhm` | `jhbuild make` | +| `jhr` | `jhbuild run` | +| `jhrd` | `jhbuild rdepends` | +| `jhsd` | `jhbuild sysdeps` | +| `jhu` | `jhbuild update` | +| `jhuo` | `jhbuild updateone` | +| `jhun` | `jhbuild uninstall` | +| `jhsh` | `jhbuild shell` | +| `jht` | `jhbuild tinderbox` | diff --git a/plugins/jhbuild/jhbuild.plugin.zsh b/plugins/jhbuild/jhbuild.plugin.zsh index fed1bc9fc..416745d27 100644 --- a/plugins/jhbuild/jhbuild.plugin.zsh +++ b/plugins/jhbuild/jhbuild.plugin.zsh @@ -1,5 +1,6 @@ -# Aliases -# +# JHBuild Aliases + +# Base alias jh='jhbuild' # Build alias jhb='jhbuild build' @@ -7,12 +8,14 @@ alias jhbo='jhbuild buildone' # Checks alias jhckb='jhbuild checkbranches' alias jhckm='jhbuild checkmodulesets' -# Info & list +# Info & List alias jhi='jhbuild info' alias jhl='jhbuild list' # Clean alias jhc='jhbuild clean' alias jhco='jhbuild cleanone' +# Make +alias jhm='jhbuild make' # Run alias jhr='jhbuild run' # Depends @@ -23,6 +26,7 @@ alias jhu='jhbuild update' alias jhuo='jhbuild updateone' # Uninstall alias jhun='jhbuild uninstall' - - - +# Shell +alias jhsh='jhbuild shell' +# Tinderbox +alias jht='jhbuild tinderbox' diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh index cc447b87e..92688c53c 100644 --- a/plugins/kubectl/kubectl.plugin.zsh +++ b/plugins/kubectl/kubectl.plugin.zsh @@ -14,7 +14,7 @@ fi alias k=kubectl # Execute a kubectl command against all namespaces -alias kca='f(){ kubectl "$@" --all-namespaces; unset -f f; }; f' +alias kca='_kca(){ kubectl "$@" --all-namespaces; unset -f _kca; }; _kca' # Apply a YML file alias kaf='kubectl apply -f' diff --git a/plugins/macports/_port b/plugins/macports/_port index 06d7fb426..6a9ebe0c6 100644 --- a/plugins/macports/_port +++ b/plugins/macports/_port @@ -41,6 +41,8 @@ subcmds=( 'patch' 'pkg' 'provides' +'rdependents' +'rdeps' 'rpmpackage' 'search' 'selfupdate' diff --git a/plugins/ng/README.md b/plugins/ng/README.md index 94a450c18..29ac15aa4 100644 --- a/plugins/ng/README.md +++ b/plugins/ng/README.md @@ -1,37 +1,10 @@ -## NG Plugin +# ng plugin -This [ng plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/ng) - adds completion support for Angular's CLI (named ng). +This plugin adds autocompletion support for [Angular's CLI](https://github.com/angular/angular-cli) +(named `ng`). -Ng is hosted on [ng home](https://github.com/catull/angular-cli) - -It is used to generate Angular 2 app "stubs", build those apps, configure them, -test them, lint them etc. - -Ahem, "stubs" is not what Angular engineers refer to the items ng can generate -for you. - -"Stubs" can be any one of: -- class -- component -- directive -- enum -- module -- pipe -- route -- service - -At the moment, `ng completion` creates a very rough completion for Zsh and -Bash. - -It is missing most of the options and a few arguments. -In future, this plugin may be shortened to simply being +To use it, add `ng` to the plugins array of your zshrc file: ```zsh -eval `ng completion` +plugins=(... ng) ``` - -There is hope this materialises in the 21st century. - -### CONTRIBUTOR - - Carlo Dapor ([catull](https://github.com/catull)) diff --git a/plugins/nmap/README.md b/plugins/nmap/README.md index 5cd646277..0a60068c2 100644 --- a/plugins/nmap/README.md +++ b/plugins/nmap/README.md @@ -1,37 +1,27 @@ -# Nmap aliases plugin +# Nmap plugin -Adds some useful aliases for nmap similar to the profiles in zenmap. +Adds some useful aliases for [Nmap](https://nmap.org/) similar to the profiles in zenmap. -Nmap options are: - * -sS - TCP SYN scan - * -v - verbose - * -T1 - timing of scan. Options are paranoid (0), sneaky (1), polite (2), normal (3), aggressive (4), and insane (5) - * -sF - FIN scan (can sneak through non-stateful firewalls) - * -PE - ICMP echo discovery probe - * -PP - timestamp discovery probe - * -PY - SCTP init ping - * -g - use given number as source port - * -A - enable OS detection, version detection, script scanning, and traceroute (aggressive) - * -O - enable OS detection - * -sA - TCP ACK scan - * -F - fast scan - * --script=vulscan - also access vulnerabilities in target +To use it, add `nmap` to the plugins array in your zshrc file: -## Aliases explained +```zsh +plugins=(... nmap) +``` - * nmap_open_ports - Scan for open ports on target - * nmap_list_interfaces - List all network interfaces on host where the command runs - * nmap_slow - Slow scan that avoids to spam the targets logs - * nmap_fin - Scan to see if hosts are up with TCP FIN scan - * nmap_full - Aggressive full scan that scans all ports, tries to determine OS and service versions - * nmap_check_for_firewall - TCP ACK scan to check for firewall existence - * nmap_ping_through_firewall - Host discovery with SYN and ACK probes instead of just pings to avoid firewall - restrictions - * nmap_fast - Fast scan of the top 300 popular ports - * nmap_detect_versions - Detects versions of services and OS, runs on all ports - * nmap_check_for_vulns - Uses vulscan script to check target services for vulnerabilities - * nmap_full_udp - Same as full but via UDP - * nmap_traceroute - Try to traceroute using the most common ports - * nmap_full_with_scripts - Same as nmap_full but also runs all the scripts - * nmap_web_safe_osscan - Little "safer" scan for OS version as connecting to only HTTP and HTTPS ports doesn't look so attacking. +## Aliases +- `nmap_open_ports`: scan for open ports on target. +- `nmap_list_interfaces`: list all network interfaces on host where the command runs. +- `nmap_slow`: slow scan that avoids to spam the targets logs. +- `nmap_fin`: scan to see if hosts are up with TCP FIN scan. +- `nmap_full`: aggressive full scan that scans all ports, tries to determine OS and service versions. +- `nmap_check_for_firewall`: TCP ACK scan to check for firewall existence. +- `nmap_ping_through_firewall`: host discovery with SYN and ACK probes instead of just pings to avoid firewall restrictions. +- `nmap_fast`: fast scan of the top 300 popular ports. +- `nmap_detect_versions`: detects versions of services and OS, runs on all ports. +- `nmap_check_for_vulns`: uses vulscan script to check target services for vulnerabilities. +- `nmap_full_udp`: same as full but via UDP. +- `nmap_traceroute`: try to traceroute using the most common ports. +- `nmap_full_with_scripts`: same as nmap_full but also runs all the scripts. +- `nmap_web_safe_osscan`: little "safer" scan for OS version as connecting to only HTTP and HTTPS ports doesn't look so attacking. +- `nmap_ping_scan`: ICMP scan for active hosts. diff --git a/plugins/nmap/nmap.plugin.zsh b/plugins/nmap/nmap.plugin.zsh index 8c691bdaa..406870f00 100644 --- a/plugins/nmap/nmap.plugin.zsh +++ b/plugins/nmap/nmap.plugin.zsh @@ -29,4 +29,4 @@ alias nmap_full_udp="sudo nmap -sS -sU -T4 -A -v -PE -PS22,25,80 -PA21,23,80,443 alias nmap_traceroute="sudo nmap -sP -PE -PS22,25,80 -PA21,23,80,3389 -PU -PO --traceroute " alias nmap_full_with_scripts="sudo nmap -sS -sU -T4 -A -v -PE -PP -PS21,22,23,25,80,113,31339 -PA80,113,443,10042 -PO --script all " alias nmap_web_safe_osscan="sudo nmap -p 80,443 -O -v --osscan-guess --fuzzy " - +alias nmap_ping_scan="nmap -n -sP" diff --git a/plugins/npm/npm.plugin.zsh b/plugins/npm/npm.plugin.zsh index f62174a4f..87c68f3fb 100644 --- a/plugins/npm/npm.plugin.zsh +++ b/plugins/npm/npm.plugin.zsh @@ -1,14 +1,16 @@ (( $+commands[npm] )) && { - __NPM_COMPLETION_FILE="${ZSH_CACHE_DIR:-$ZSH/cache}/npm_completion" - - if [[ ! -f $__NPM_COMPLETION_FILE ]]; then - npm completion >! $__NPM_COMPLETION_FILE 2>/dev/null - [[ $? -ne 0 ]] && rm -f $__NPM_COMPLETION_FILE - fi - - [[ -f $__NPM_COMPLETION_FILE ]] && source $__NPM_COMPLETION_FILE - - unset __NPM_COMPLETION_FILE + rm -f "${ZSH_CACHE_DIR:-$ZSH/cache}/npm_completion" + + _npm_completion() { + local si=$IFS + compadd -- $(COMP_CWORD=$((CURRENT-1)) \ + COMP_LINE=$BUFFER \ + COMP_POINT=0 \ + npm completion -- "${words[@]}" \ + 2>/dev/null) + IFS=$si + } + compdef _npm_completion npm } # Install dependencies globally diff --git a/plugins/python/README.md b/plugins/python/README.md index 2d955c5cb..e391bcfd4 100644 --- a/plugins/python/README.md +++ b/plugins/python/README.md @@ -14,3 +14,4 @@ plugins=(... python) | `pyfind` | Finds .py files recursively in the current directory | | `pyclean [dirs]` | Deletes byte-code and cache files from a list of directories or the current one | | `pygrep <text>` | Looks for `text` in .py files | +| `ipython` | Runs the appropriate `ipython` version according to the activated virtualenv | diff --git a/plugins/python/python.plugin.zsh b/plugins/python/python.plugin.zsh index f39cd80b7..62855fca2 100644 --- a/plugins/python/python.plugin.zsh +++ b/plugins/python/python.plugin.zsh @@ -14,3 +14,5 @@ function pyclean() { # Grep among .py files alias pygrep='grep -r --include="*.py"' +# Run proper IPython regarding current virtualenv (if any) +alias ipython="python -c 'import IPython; IPython.terminal.ipapp.launch_new_instance()'" diff --git a/plugins/systemd/README.md b/plugins/systemd/README.md index d91329290..3fa1d2118 100644 --- a/plugins/systemd/README.md +++ b/plugins/systemd/README.md @@ -51,3 +51,44 @@ plugins=(... systemd) You can use the above aliases as `--user` by using the prefix `scu` instead of `sc`. For example: `scu-list-units` will be aliased to `systemctl --user list-units`. + +### Unit Status Prompt + +You can add a token to your prompt in a similar way to the gitfast plugin. To add the token +to your prompt, drop `$(systemd_prompt_info [unit]...)` into your prompt (more than one unit +may be specified). + +The plugin will add the following to your prompt for each `$unit`. +``` +<prefix><unit>:<active|notactive><suffix> +``` +You can control these parts with the following variables: + +- `<prefix>`: Set `$ZSH_THEME_SYSTEMD_PROMPT_PREFIX`. + +- `<suffix>`: Set `$ZSH_THEME_SYSTEMD_PROMPT_SUFFIX`. + +- `<unit>`: name passed as parameter to the function. If you want it to be in ALL CAPS, + you can set the variable `$ZSH_THEME_SYSTEMD_PROMPT_CAPS` to a non-empty string. + +- `<active>`: shown if the systemd unit is active. + Set `$ZSH_THEME_SYSTEMD_PROMPT_ACTIVE`. + +- `<notactive>`: shown if the systemd unit is *not* active. + Set `$ZSH_THEME_SYSTEMD_PROMPT_NOTACTIVE`. + +For example, if your prompt contains `PROMPT='$(systemd_prompt_info dhcpd httpd)'` and you set the following variables: + +``` +ZSH_THEME_SYSTEMD_PROMPT_PREFIX="[" +ZSH_THEME_SYSTEMD_PROMPT_SUFFIX="]" +ZSH_THEME_SYSTEMD_PROMPT_ACTIVE="+" +ZSH_THEME_SYSTEMD_PROMPT_NOTACTIVE="X" +ZSH_THEME_SYSTEMD_PROMPT_CAPS=1 +``` + +If `dhcpd` is running, and `httpd` is not, then your prompt will look like this: + +``` +[DHCPD: +][HTTPD: X] +``` diff --git a/plugins/systemd/systemd.plugin.zsh b/plugins/systemd/systemd.plugin.zsh index 201ffd998..f2d1d6f1c 100644 --- a/plugins/systemd/systemd.plugin.zsh +++ b/plugins/systemd/systemd.plugin.zsh @@ -73,3 +73,18 @@ alias sc-mask-now="sc-mask --now" alias scu-enable-now="scu-enable --now" alias scu-disable-now="scu-disable --now" alias scu-mask-now="scu-mask --now" + +function systemd_prompt_info { + local unit + for unit in $@; do + echo -n "$ZSH_THEME_SYSTEMD_PROMPT_PREFIX" + [[ -n "$ZSH_THEME_SYSTEMD_PROMPT_CAPS" ]] && echo "${(U)unit}:" || echo "$unit:" + if systemctl is-active $unit &>/dev/null; then + echo -n "$ZSH_THEME_SYSTEMD_PROMPT_ACTIVE" + else + echo -n "$ZSH_THEME_SYSTEMD_PROMPT_NOTACTIVE" + fi + echo -n "$ZSH_THEME_SYSTEMD_PROMPT_SUFFIX" + done +} + diff --git a/plugins/themes/_theme b/plugins/themes/_theme deleted file mode 100644 index 8214ddb0d..000000000 --- a/plugins/themes/_theme +++ /dev/null @@ -1,3 +0,0 @@ -#compdef theme - -_arguments "1: :($(lstheme | tr "\n" " "))" diff --git a/plugins/themes/themes.plugin.zsh b/plugins/themes/themes.plugin.zsh index 2cd0ee327..1fbde5b64 100644 --- a/plugins/themes/themes.plugin.zsh +++ b/plugins/themes/themes.plugin.zsh @@ -1,26 +1,27 @@ -function theme -{ - if [ -z "$1" ] || [ "$1" = "random" ]; then - themes=($ZSH/themes/*zsh-theme) - N=${#themes[@]} - ((N=(RANDOM%N)+1)) - RANDOM_THEME=${themes[$N]} - source "$RANDOM_THEME" - echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..." +function theme { + : ${1:=random} # Use random theme if none provided + + if [[ -f "$ZSH_CUSTOM/$1.zsh-theme" ]]; then + source "$ZSH_CUSTOM/$1.zsh-theme" + elif [[ -f "$ZSH_CUSTOM/themes/$1.zsh-theme" ]]; then + source "$ZSH_CUSTOM/themes/$1.zsh-theme" + elif [[ -f "$ZSH/themes/$1.zsh-theme" ]]; then + source "$ZSH/themes/$1.zsh-theme" else - if [ -f "$ZSH_CUSTOM/themes/$1.zsh-theme" ] - then - source "$ZSH_CUSTOM/themes/$1.zsh-theme" - else - source "$ZSH/themes/$1.zsh-theme" - fi + echo "$0: Theme '$1' not found" + return 1 fi } -function lstheme -{ +function _theme { + _arguments "1: :($(lstheme))" +} + +compdef _theme theme + +function lstheme { # Resources: # http://zsh.sourceforge.net/Doc/Release/Expansion.html#Modifiers # http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Qualifiers - print -l {$ZSH,$ZSH_CUSTOM}/themes/*.zsh-theme(N:t:r) + print "$ZSH_CUSTOM"/*.zsh-theme(N:t:r) {"$ZSH_CUSTOM","$ZSH"}/themes/*.zsh-theme(N:t:r) } diff --git a/plugins/vagrant/README.md b/plugins/vagrant/README.md index f6ea87b0e..331bfa143 100644 --- a/plugins/vagrant/README.md +++ b/plugins/vagrant/README.md @@ -8,3 +8,33 @@ To use it, add `vagrant` to the plugins array in your zshrc file: plugins=(... vagrant) ``` +## Aliases + +| Alias | Command | +|---------|------------------------------| +| `vgi` | `vagrant init` | +| `vup` | `vagrant up` | +| `vd` | `vagrant destroy` | +| `vdf` | `vagrant destroy -f` | +| `vssh` | `vagrant ssh` | +| `vsshc` | `vagrant ssh-config` | +| `vrdp` | `vagrant rdp` | +| `vh` | `vagrant halt` | +| `vssp` | `vagrant suspend` | +| `vst` | `vagrant status` | +| `vre` | `vagrant resume` | +| `vgs` | `vagrant global-status` | +| `vpr` | `vagrant provision` | +| `vr` | `vagrant reload` | +| `vrp` | `vagrant reload --provision` | +| `vp` | `vagrant push` | +| `vsh` | `vagrant share` | +| `vba` | `vagrant box add` | +| `vbr` | `vagrant box remove` | +| `vbl` | `vagrant box list` | +| `vbo` | `vagrant box outdated` | +| `vbu` | `vagrant box update` | +| `vpli` | `vagrant plugin install` | +| `vpll` | `vagrant plugin list` | +| `vplun` | `vagrant plugin uninstall` | +| `vplu` | `vagrant plugin update` | diff --git a/plugins/vagrant/vagrant.plugin.zsh b/plugins/vagrant/vagrant.plugin.zsh new file mode 100644 index 000000000..a4e9b06c2 --- /dev/null +++ b/plugins/vagrant/vagrant.plugin.zsh @@ -0,0 +1,33 @@ +alias vgi="vagrant init" + +alias vup="vagrant up" +alias vd="vagrant destroy" +alias vdf="vagrant destroy -f" + +alias vssh="vagrant ssh" +alias vsshc="vagrant ssh-config" +alias vrdp="vagrant rdp" + +alias vh="vagrant halt" +alias vssp="vagrant suspend" +alias vst="vagrant status" +alias vre="vagrant resume" +alias vgs="vagrant global-status" + +alias vpr="vagrant provision" +alias vr="vagrant reload" +alias vrp="vagrant reload --provision" + +alias vp="vagrant push" +alias vsh="vagrant share" + +alias vba="vagrant box add" +alias vbr="vagrant box remove" +alias vbl="vagrant box list" +alias vbo="vagrant box outdated" +alias vbu="vagrant box update" + +alias vpli="vagrant plugin install" +alias vpll="vagrant plugin list" +alias vplun="vagrant plugin uninstall" +alias vplu="vagrant plugin update" diff --git a/plugins/vscode/README.md b/plugins/vscode/README.md index 2c6530650..469c57ea8 100644 --- a/plugins/vscode/README.md +++ b/plugins/vscode/README.md @@ -8,6 +8,15 @@ To start using it, add the `vscode` plugin to your `plugins` array in `~/.zshrc` plugins=(... vscode) ``` +## Requirements + +To use VS Code in the terminal **in macOS**, first you need to install the `code` command in the PATH, +otherwise you might receive this message: `zsh: command not found: code`. + +[As the docs say](https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line), open +the Command Palette via (F1 or ⇧⌘P) and type shell command to find the Shell Command: +> Install 'code' command in PATH + ## VS Code Insiders 🍏 **If you are only using [VS Code Insiders](https://code.visualstudio.com/insiders/), the plugin will automatically bind to your Insiders installation.** diff --git a/plugins/web-search/README.md b/plugins/web-search/README.md index d04042506..9c01f0724 100644 --- a/plugins/web-search/README.md +++ b/plugins/web-search/README.md @@ -39,6 +39,7 @@ Available search contexts are: | `qwant` | `https://www.qwant.com/?q=` | | `givero` | `https://www.givero.com/search?q=` | | `stackoverflow` | `https://stackoverflow.com/search?q=` | +| `wolframalpha` | `https://wolframalpha.com/input?i=` | Also there are aliases for bang-searching DuckDuckGo: diff --git a/plugins/web-search/web-search.plugin.zsh b/plugins/web-search/web-search.plugin.zsh index 5b76eeae2..f975bad7a 100644 --- a/plugins/web-search/web-search.plugin.zsh +++ b/plugins/web-search/web-search.plugin.zsh @@ -19,6 +19,7 @@ function web_search() { qwant "https://www.qwant.com/?q=" givero "https://www.givero.com/search?q=" stackoverflow "https://stackoverflow.com/search?q=" + wolframalpha "https://www.wolframalpha.com/input/?i=" ) # check whether the search engine is supported @@ -55,6 +56,7 @@ alias goodreads='web_search goodreads' alias qwant='web_search qwant' alias givero='web_search givero' alias stackoverflow='web_search stackoverflow' +alias wolframalpha='web_search wolframalpha' #add your own !bang searches here alias wiki='web_search duckduckgo \!w' diff --git a/plugins/zsh-interactive-cd/zsh-interactive-cd.plugin.zsh b/plugins/zsh-interactive-cd/zsh-interactive-cd.plugin.zsh index 0f15aeef0..b0520c239 100644 --- a/plugins/zsh-interactive-cd/zsh-interactive-cd.plugin.zsh +++ b/plugins/zsh-interactive-cd/zsh-interactive-cd.plugin.zsh @@ -144,4 +144,5 @@ zic-completion() { } zle -N zic-completion -bindkey '^I' zic-completion +bindkey -M emacs '^I' zic-completion +bindkey -M viins '^I' zic-completion diff --git a/themes/af-magic.zsh-theme b/themes/af-magic.zsh-theme index 30e997f8c..148991fec 100644 --- a/themes/af-magic.zsh-theme +++ b/themes/af-magic.zsh-theme @@ -2,29 +2,28 @@ # Repo: https://github.com/andyfleming/oh-my-zsh # Direct Link: https://github.com/andyfleming/oh-my-zsh/blob/master/themes/af-magic.zsh-theme -if [ $UID -eq 0 ]; then NCOLOR="red"; else NCOLOR="green"; fi -local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" -# primary prompt -PROMPT='$FG[237]${(l.COLUMNS..-.)}%{$reset_color%} -$FG[032]%~\ -$(git_prompt_info)$(hg_prompt_info) \ -$FG[105]%(!.#.»)%{$reset_color%} ' -PROMPT2='%{$fg[red]%}\ %{$reset_color%}' -RPS1='${return_code}' +# settings +typeset +H return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" +typeset +H my_gray="$FG[237]" +typeset +H my_orange="$FG[214]" +# separator dashes size +function afmagic_dashes { + [[ -n "${VIRTUAL_ENV-}" && -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" && "$PS1" = \(* ]] \ + && echo $(( COLUMNS - ${#VIRTUAL_ENV} - 3 )) \ + || echo $COLUMNS +} -# color vars -eval my_gray='$FG[237]' -eval my_orange='$FG[214]' +# primary prompt +PS1='$FG[237]${(l.$(afmagic_dashes)..-.)}%{$reset_color%} +$FG[032]%~$(git_prompt_info)$(hg_prompt_info) $FG[105]%(!.#.»)%{$reset_color%} ' +PS2='%{$fg[red]%}\ %{$reset_color%}' +RPS1='${return_code}' # right prompt -if type "virtualenv_prompt_info" > /dev/null -then - RPROMPT="${RPROMPT}"'$FG[078]$(virtualenv_prompt_info)%{$reset_color%} $my_gray%n@%m%{$reset_color%}%' -else - RPROMPT="${RPROMPT}"'$my_gray%n@%m%{$reset_color%}%' -fi +(( $+functions[virtualenv_prompt_info] )) && RPS1+='$(virtualenv_prompt_info)' +RPS1+=' $my_gray%n@%m%{$reset_color%}%' # git settings ZSH_THEME_GIT_PROMPT_PREFIX="$FG[075]($FG[078]" @@ -37,3 +36,7 @@ ZSH_THEME_HG_PROMPT_PREFIX="$FG[075]($FG[078]" ZSH_THEME_HG_PROMPT_CLEAN="" ZSH_THEME_HG_PROMPT_DIRTY="$my_orange*%{$reset_color%}" ZSH_THEME_HG_PROMPT_SUFFIX="$FG[075])%{$reset_color%}" + +# virtualenv settings +ZSH_THEME_VIRTUALENV_PREFIX=" $FG[075][" +ZSH_THEME_VIRTUALENV_SUFFIX="]%{$reset_color%}" diff --git a/themes/agnoster.zsh-theme b/themes/agnoster.zsh-theme index 05a50cd2b..89b75aa55 100644 --- a/themes/agnoster.zsh-theme +++ b/themes/agnoster.zsh-theme @@ -140,24 +140,30 @@ prompt_git() { } prompt_bzr() { - (( $+commands[bzr] )) || return - if (bzr status >/dev/null 2>&1); then - status_mod=`bzr status | head -n1 | grep "modified" | wc -m` - status_all=`bzr status | head -n1 | wc -m` - revision=`bzr log | head -n2 | tail -n1 | sed 's/^revno: //'` - if [[ $status_mod -gt 0 ]] ; then - prompt_segment yellow black - echo -n "bzr@"$revision "✚ " - else - if [[ $status_all -gt 0 ]] ; then - prompt_segment yellow black - echo -n "bzr@"$revision - else - prompt_segment green black - echo -n "bzr@"$revision - fi - fi + (( $+commands[bzr] )) || return + + # Test if bzr repository in directory hierarchy + local dir="$PWD" + while [[ ! -d "$dir/.bzr" ]]; do + [[ "$dir" = "/" ]] && return + dir="${dir:h}" + done + + local bzr_status status_mod status_all revision + if bzr_status=$(bzr status 2>&1); then + status_mod=$(echo -n "$bzr_status" | head -n1 | grep "modified" | wc -m) + status_all=$(echo -n "$bzr_status" | head -n1 | wc -m) + revision=$(bzr log -r-1 --log-format line | cut -d: -f1) + if [[ $status_mod -gt 0 ]] ; then + prompt_segment yellow black "bzr@$revision ✚" + else + if [[ $status_all -gt 0 ]] ; then + prompt_segment yellow black "bzr@$revision" + else + prompt_segment green black "bzr@$revision" + fi fi + fi } prompt_hg() { diff --git a/themes/avit.zsh-theme b/themes/avit.zsh-theme index aec14e4a6..0261f0ff3 100644 --- a/themes/avit.zsh-theme +++ b/themes/avit.zsh-theme @@ -1,27 +1,20 @@ # AVIT ZSH Theme -PROMPT=' -$(_user_host)${_current_dir} $(git_prompt_info) $(_ruby_version) -%{$fg[$CARETCOLOR]%}▶%{$resetcolor%} ' - -PROMPT2='%{$fg[$CARETCOLOR]%}◀%{$reset_color%} ' +# settings +typeset +H _current_dir="%{$fg_bold[blue]%}%3~%{$reset_color%} " +typeset +H _return_status="%{$fg_bold[red]%}%(?..⍉)%{$reset_color%}" +typeset +H _hist_no="%{$fg[grey]%}%h%{$reset_color%}" -RPROMPT='$(_vi_status)%{$(echotc UP 1)%}$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}' +PROMPT=' +$(_user_host)${_current_dir} $(git_prompt_info) $(ruby_prompt_info) +%{%(!.%F{red}.%F{white})%}▶%{$resetcolor%} ' -local _current_dir="%{$fg_bold[blue]%}%3~%{$reset_color%} " -local _return_status="%{$fg_bold[red]%}%(?..⍉)%{$reset_color%}" -local _hist_no="%{$fg[grey]%}%h%{$reset_color%}" +PROMPT2='%{%(!.%F{red}.%F{white})%}◀%{$reset_color%} ' -function _current_dir() { - local _max_pwd_length="65" - if [[ $(echo -n $PWD | wc -c) -gt ${_max_pwd_length} ]]; then - echo "%{$fg_bold[blue]%}%-2~ ... %3~%{$reset_color%} " - else - echo "%{$fg_bold[blue]%}%~%{$reset_color%} " - fi -} +RPROMPT='$(vi_mode_prompt_info)%{$(echotc UP 1)%}$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}' function _user_host() { + local me if [[ -n $SSH_CONNECTION ]]; then me="%n@%m" elif [[ $LOGNAME != $USER ]]; then @@ -32,61 +25,41 @@ function _user_host() { fi } -function _vi_status() { - if {echo $fpath | grep -q "plugins/vi-mode"}; then - echo "$(vi_mode_prompt_info)" - fi -} - -function _ruby_version() { - if {echo $fpath | grep -q "plugins/rvm"}; then - echo "%{$fg[grey]%}$(rvm_prompt_info)%{$reset_color%}" - elif {echo $fpath | grep -q "plugins/rbenv"}; then - echo "%{$fg[grey]%}$(rbenv_prompt_info)%{$reset_color%}" - fi -} - # Determine the time since last commit. If branch is clean, # use a neutral color, otherwise colors will vary according to time. function _git_time_since_commit() { -# Only proceed if there is actually a commit. + local last_commit now seconds_since_last_commit + local minutes hours days years commit_age + # Only proceed if there is actually a commit. if last_commit=$(git log --pretty=format:'%at' -1 2> /dev/null); then now=$(date +%s) seconds_since_last_commit=$((now-last_commit)) # Totals minutes=$((seconds_since_last_commit / 60)) - hours=$((seconds_since_last_commit/3600)) - - # Sub-hours and sub-minutes - days=$((seconds_since_last_commit / 86400)) - sub_hours=$((hours % 24)) - sub_minutes=$((minutes % 60)) - - if [ $hours -ge 24 ]; then - commit_age="${days}d" - elif [ $minutes -gt 60 ]; then - commit_age="${sub_hours}h${sub_minutes}m" + hours=$((minutes / 60)) + days=$((hours / 24)) + years=$((days / 365)) + + if [[ $years -gt 0 ]]; then + commit_age="${years}y$((days % 365 ))d" + elif [[ $days -gt 0 ]]; then + commit_age="${days}d$((hours % 24))h" + elif [[ $hours -gt 0 ]]; then + commit_age+="${hours}h$(( minutes % 60 ))m" else commit_age="${minutes}m" fi - color=$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL - echo "$color$commit_age%{$reset_color%}" + echo "${ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL}${commit_age}%{$reset_color%}" fi } -if [[ $USER == "root" ]]; then - CARETCOLOR="red" -else - CARETCOLOR="white" -fi - MODE_INDICATOR="%{$fg_bold[yellow]%}❮%{$reset_color%}%{$fg[yellow]%}❮❮%{$reset_color%}" +# Git prompt settings ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" - ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}✗%{$reset_color%}" ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg[green]%}✔%{$reset_color%}" ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[green]%}✚ " @@ -96,6 +69,10 @@ ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[blue]%}▴ " ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[cyan]%}§ " ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[white]%}◒ " +# Ruby prompt settings +ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg[grey]%}" +ZSH_THEME_RUBY_PROMPT_SUFFIX="%{$reset_color%}" + # Colors vary depending on time lapsed. ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}" ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%{$fg[yellow]%}" diff --git a/themes/norm.zsh-theme b/themes/norm.zsh-theme index 13077ccf5..bd7ca568a 100644 --- a/themes/norm.zsh-theme +++ b/themes/norm.zsh-theme @@ -1,4 +1,7 @@ -PROMPT='%{$fg[yellow]%}λ %m %{$fg[green]%}%c %{$fg[yellow]%}→ $(git_prompt_info)%{$reset_color%}' +PROMPT='%{$fg[yellow]%}λ %m %{$fg[green]%}%c %{$fg[yellow]%}→ $(git_prompt_info)$(hg_prompt_info)%{$reset_color%}' ZSH_THEME_GIT_PROMPT_PREFIX="λ %{$fg[blue]%}git %{$fg[red]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg[yellow]%} → %{$reset_color%}" +ZSH_THEME_HG_PROMPT_PREFIX="λ %{$fg[blue]%}hg %{$fg[red]%}" +ZSH_THEME_HG_PROMPT_SUFFIX="%{$fg[yellow]%} → %{$reset_color%}" + diff --git a/themes/random.zsh-theme b/themes/random.zsh-theme new file mode 100644 index 000000000..43f6cbb60 --- /dev/null +++ b/themes/random.zsh-theme @@ -0,0 +1,38 @@ +# Make themes a unique array +typeset -Ua themes + +if [[ "${(t)ZSH_THEME_RANDOM_CANDIDATES}" = array && ${#ZSH_THEME_RANDOM_CANDIDATES[@]} -gt 0 ]]; then + # Use ZSH_THEME_RANDOM_CANDIDATES if properly defined + themes=($ZSH_THEME_RANDOM_CANDIDATES) +else + # Look for themes in $ZSH_CUSTOM and $ZSH and add only the theme name + themes=( + "$ZSH_CUSTOM"/*.zsh-theme(N:t:r) + "$ZSH_CUSTOM"/themes/*.zsh-theme(N:t:r) + "$ZSH"/themes/*.zsh-theme(N:t:r) + ) + # Remove blacklisted themes from the list + for theme in ${ZSH_THEME_RANDOM_BLACKLIST[@]}; do + themes=("${(@)themes:#$theme}") + done +fi + +# Choose a theme out of the pool of candidates +N=${#themes[@]} +(( N = (RANDOM%N) + 1 )) +RANDOM_THEME="${themes[$N]}" +unset N themes theme + +# Source theme +if [[ -f "$ZSH_CUSTOM/$RANDOM_THEME.zsh-theme" ]]; then + source "$ZSH_CUSTOM/$RANDOM_THEME.zsh-theme" +elif [[ -f "$ZSH_CUSTOM/themes/$RANDOM_THEME.zsh-theme" ]]; then + source "$ZSH_CUSTOM/themes/$RANDOM_THEME.zsh-theme" +elif [[ -f "$ZSH/themes/$RANDOM_THEME.zsh-theme" ]]; then + source "$ZSH/themes/$RANDOM_THEME.zsh-theme" +else + echo "[oh-my-zsh] Random theme '${RANDOM_THEME}' not found" + return 1 +fi + +echo "[oh-my-zsh] Random theme '${RANDOM_THEME}' loaded" diff --git a/tools/install.sh b/tools/install.sh index ae248be89..08f3db1e3 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -20,12 +20,14 @@ # BRANCH - branch to check out immediately after install (default: master) # # Other options: -# CHSH - 'no' means the installer will not change the default shell (default: yes) -# RUNZSH - 'no' means the installer will not run zsh after the install (default: yes) +# CHSH - 'no' means the installer will not change the default shell (default: yes) +# RUNZSH - 'no' means the installer will not run zsh after the install (default: yes) +# KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no) # # You can also pass some arguments to the install script to set some these options: # --skip-chsh: has the same behavior as setting CHSH to 'no' # --unattended: sets both CHSH and RUNZSH to 'no' +# --keep-zshrc: sets KEEP_ZSHRC to 'yes' # For example: # sh install.sh --unattended # @@ -40,6 +42,7 @@ BRANCH=${BRANCH:-master} # Other options CHSH=${CHSH:-yes} RUNZSH=${RUNZSH:-yes} +KEEP_ZSHRC=${KEEP_ZSHRC:-no} command_exists() { @@ -111,6 +114,11 @@ setup_zshrc() { # Must use this exact name so uninstall.sh can find it OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then + # Skip this if the user doesn't want to replace an existing .zshrc + if [ $KEEP_ZSHRC = yes ]; then + echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Keeping...${RESET}" + return + fi if [ -e "$OLD_ZSHRC" ]; then OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)" if [ -e "$OLD_OLD_ZSHRC" ]; then @@ -129,10 +137,9 @@ setup_zshrc() { echo "${GREEN}Using the Oh My Zsh template file and adding it to ~/.zshrc.${RESET}" - cp "$ZSH/templates/zshrc.zsh-template" ~/.zshrc sed "/^export ZSH=/ c\\ export ZSH=\"$ZSH\" -" ~/.zshrc > ~/.zshrc-omztemp +" "$ZSH/templates/zshrc.zsh-template" > ~/.zshrc-omztemp mv -f ~/.zshrc-omztemp ~/.zshrc echo @@ -228,6 +235,7 @@ main() { case $1 in --unattended) RUNZSH=no; CHSH=no ;; --skip-chsh) CHSH=no ;; + --keep-zshrc) KEEP_ZSHRC=yes ;; esac shift done diff --git a/tools/upgrade.sh b/tools/upgrade.sh index 3005e6542..0dc84e214 100644 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -38,7 +38,7 @@ if [ -n "$remote" ]; then fi printf "${BLUE}%s${NORMAL}\n" "Updating Oh My Zsh" -if git pull --rebase --stat origin master +if git pull --rebase --autostash --stat origin master then printf '%s' "$GREEN" printf '%s\n' ' __ __ ' |