diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/ag/README.md | 2 | ||||
-rw-r--r-- | plugins/aws/aws.plugin.zsh | 66 | ||||
-rw-r--r-- | plugins/cloudapp/README.md | 26 | ||||
-rw-r--r-- | plugins/cloudapp/cloudapp.plugin.zsh | 4 | ||||
-rw-r--r-- | plugins/copybuffer/copybuffer.plugin.zsh | 2 | ||||
-rw-r--r-- | plugins/dirhistory/README.md | 3 | ||||
-rw-r--r-- | plugins/extract/README.md | 2 | ||||
-rw-r--r-- | plugins/extract/_extract | 2 | ||||
-rw-r--r-- | plugins/extract/extract.plugin.zsh | 147 | ||||
-rw-r--r-- | plugins/fedora/README.md | 1 | ||||
-rw-r--r-- | plugins/fedora/fedora.plugin.zsh | 3 | ||||
-rw-r--r-- | plugins/fnm/.gitignore | 2 | ||||
-rw-r--r-- | plugins/fnm/README.md | 9 | ||||
-rw-r--r-- | plugins/fnm/fnm.plugin.zsh | 12 | ||||
-rw-r--r-- | plugins/git/README.md | 35 | ||||
-rw-r--r-- | plugins/git/git.plugin.zsh | 19 | ||||
-rw-r--r-- | plugins/github/README.md | 4 | ||||
-rw-r--r-- | plugins/gnu-utils/gnu-utils.plugin.zsh | 2 | ||||
-rw-r--r-- | plugins/go/README.md | 1 | ||||
-rw-r--r-- | plugins/go/go.plugin.zsh | 3 | ||||
-rw-r--r-- | plugins/invoke/README.md | 10 | ||||
-rw-r--r-- | plugins/invoke/invoke.plugin.zsh | 5 | ||||
-rw-r--r-- | plugins/octozen/README.md | 12 | ||||
-rw-r--r-- | plugins/octozen/octozen.plugin.zsh | 11 | ||||
-rw-r--r-- | plugins/pyenv/pyenv.plugin.zsh | 83 |
25 files changed, 268 insertions, 198 deletions
diff --git a/plugins/ag/README.md b/plugins/ag/README.md index 6acc54067..1983aaa41 100644 --- a/plugins/ag/README.md +++ b/plugins/ag/README.md @@ -5,7 +5,7 @@ This plugin provides completion support for [`ag`](https://github.com/ggreer/the To use it, add ag to the plugins array in your zshrc file. ```zsh -plugins=(... aws) +plugins=(... ag) ``` ## INSTALLATION NOTES diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh index e1566b113..2d095635b 100644 --- a/plugins/aws/aws.plugin.zsh +++ b/plugins/aws/aws.plugin.zsh @@ -62,47 +62,47 @@ function acp() { read -r sess_duration fi mfa_opt=(--serial-number "$mfa_serial" --token-code "$mfa_token" --duration-seconds "${sess_duration:-3600}") + fi - # Now see whether we need to just MFA for the current role, or assume a different one - local role_arn="$(aws configure get role_arn --profile $profile)" - local sess_name="$(aws configure get role_session_name --profile $profile)" - - if [[ -n "$role_arn" ]]; then - # Means we need to assume a specified role - aws_command=(aws sts assume-role --role-arn "$role_arn" "${mfa_opt[@]}") + # Now see whether we need to just MFA for the current role, or assume a different one + local role_arn="$(aws configure get role_arn --profile $profile)" + local sess_name="$(aws configure get role_session_name --profile $profile)" - # Check whether external_id is configured to use while assuming the role - local external_id="$(aws configure get external_id --profile $profile)" - if [[ -n "$external_id" ]]; then - aws_command+=(--external-id "$external_id") - fi + if [[ -n "$role_arn" ]]; then + # Means we need to assume a specified role + aws_command=(aws sts assume-role --role-arn "$role_arn" "${mfa_opt[@]}") - # Get source profile to use to assume role - local source_profile="$(aws configure get source_profile --profile $profile)" - if [[ -z "$sess_name" ]]; then - sess_name="${source_profile:-profile}" - fi - aws_command+=(--profile="${source_profile:-profile}" --role-session-name "${sess_name}") + # Check whether external_id is configured to use while assuming the role + local external_id="$(aws configure get external_id --profile $profile)" + if [[ -n "$external_id" ]]; then + aws_command+=(--external-id "$external_id") + fi - echo "Assuming role $role_arn using profile ${source_profile:-profile}" - else - # Means we only need to do MFA - aws_command=(aws sts get-session-token --profile="$profile" "${mfa_opt[@]}") - echo "Obtaining session token for profile $profile" + # Get source profile to use to assume role + local source_profile="$(aws configure get source_profile --profile $profile)" + if [[ -z "$sess_name" ]]; then + sess_name="${source_profile:-profile}" fi + aws_command+=(--profile="${source_profile:-profile}" --role-session-name "${sess_name}") - # Format output of aws command for easier processing - aws_command+=(--query '[Credentials.AccessKeyId,Credentials.SecretAccessKey,Credentials.SessionToken]' --output text) + echo "Assuming role $role_arn using profile ${source_profile:-profile}" + else + # Means we only need to do MFA + aws_command=(aws sts get-session-token --profile="$profile" "${mfa_opt[@]}") + echo "Obtaining session token for profile $profile" + fi - # Run the aws command to obtain credentials - local -a credentials - credentials=(${(ps:\t:)"$(${aws_command[@]})"}) + # Format output of aws command for easier processing + aws_command+=(--query '[Credentials.AccessKeyId,Credentials.SecretAccessKey,Credentials.SessionToken]' --output text) - if [[ -n "$credentials" ]]; then - aws_access_key_id="${credentials[1]}" - aws_secret_access_key="${credentials[2]}" - aws_session_token="${credentials[3]}" - fi + # Run the aws command to obtain credentials + local -a credentials + credentials=(${(ps:\t:)"$(${aws_command[@]})"}) + + if [[ -n "$credentials" ]]; then + aws_access_key_id="${credentials[1]}" + aws_secret_access_key="${credentials[2]}" + aws_session_token="${credentials[3]}" fi # Switch to AWS profile diff --git a/plugins/cloudapp/README.md b/plugins/cloudapp/README.md deleted file mode 100644 index ef304edc2..000000000 --- a/plugins/cloudapp/README.md +++ /dev/null @@ -1,26 +0,0 @@ -# CloudApp plugin - -## The CloudApp API is deprecated, so the plugin will be removed shortly - -[CloudApp](https://www.getcloudapp.com) brings screen recording, screenshots, and GIF creation to the cloud, in an easy-to-use enterprise-level app. The CloudApp plugin allows you to upload a file to your CloadApp account from the command line. - -To use it, add `cloudapp` to the plugins array of your `~/.zshrc` file: - -```zsh -plugins=(... cloudapp) -``` - -## Requirements - -1. [Aaron Russell's `cloudapp_api` gem](https://github.com/aaronrussell/cloudapp_api#installation) - -2. That you set your CloudApp credentials in `~/.cloudapp` as a simple text file like below: - ``` - email - password - ``` - -## Usage - -- `cloudapp <filename>`: uploads `<filename>` to your CloudApp account, and if you're using - macOS, copies the URL to your clipboard. diff --git a/plugins/cloudapp/cloudapp.plugin.zsh b/plugins/cloudapp/cloudapp.plugin.zsh deleted file mode 100644 index a4d92a080..000000000 --- a/plugins/cloudapp/cloudapp.plugin.zsh +++ /dev/null @@ -1,4 +0,0 @@ -print -Pn "%F{yellow}" -print "[oh-my-zsh] The CloudApp API no longer works, so the cloudapp plugin will" -print "[oh-my-zsh] be removed shortly. Please remove it from your plugins list." -print -Pn "%f" diff --git a/plugins/copybuffer/copybuffer.plugin.zsh b/plugins/copybuffer/copybuffer.plugin.zsh index 483ed5a5f..87a658d93 100644 --- a/plugins/copybuffer/copybuffer.plugin.zsh +++ b/plugins/copybuffer/copybuffer.plugin.zsh @@ -5,7 +5,7 @@ copybuffer () { if which clipcopy &>/dev/null; then printf "%s" "$BUFFER" | clipcopy else - echo "clipcopy function not found. Please make sure you have Oh My Zsh installed correctly." + zle -M "clipcopy not found. Please make sure you have Oh My Zsh installed correctly." fi } diff --git a/plugins/dirhistory/README.md b/plugins/dirhistory/README.md index 223650727..602fc8284 100644 --- a/plugins/dirhistory/README.md +++ b/plugins/dirhistory/README.md @@ -17,6 +17,9 @@ plugins=(... dirhistory) | <kbd>alt</kbd> + <kbd>up</kbd> | Move into the parent directory | | <kbd>alt</kbd> + <kbd>down</kbd> | Move into the first child directory by alphabetical order | +NOTE: some terminals might override the ALT+Arrows key bindings (Windows Terminal, for example). +If these don't work check your terminal settings and change them to a different keyboard shortcut. + ## Usage This plugin allows you to navigate the history of previous current-working-directories using ALT-LEFT and ALT-RIGHT. ALT-LEFT moves back to directories that the user has changed to in the past, and ALT-RIGHT undoes ALT-LEFT. MAC users may alternately use OPT-LEFT and OPT-RIGHT. diff --git a/plugins/extract/README.md b/plugins/extract/README.md index f2e6ad1d1..44f0b05a1 100644 --- a/plugins/extract/README.md +++ b/plugins/extract/README.md @@ -21,6 +21,8 @@ plugins=(... extract) | `apk` | Android app file | | `aar` | Android library file | | `bz2` | Bzip2 file | +| `cab` | Microsoft cabinet archive | +| `cpio` | Cpio archive | | `deb` | Debian package | | `ear` | Enterprise Application aRchive | | `gz` | Gzip file | diff --git a/plugins/extract/_extract b/plugins/extract/_extract index 267c4d4e1..27b099c9e 100644 --- a/plugins/extract/_extract +++ b/plugins/extract/_extract @@ -3,5 +3,5 @@ _arguments \ '(-r --remove)'{-r,--remove}'[Remove archive.]' \ - "*::archive file:_files -g '(#i)*.(7z|Z|apk|aar|bz2|deb|ear|gz|ipa|ipsw|jar|lrz|lz4|lzma|rar|rpm|sublime-package|tar|tar.bz2|tar.gz|tar.lrz|tar.lz|tar.lz4|tar.xz|tar.zma|tar.zst|tbz|tbz2|tgz|tlz|txz|tzst|war|whl|xpi|xz|zip|zst)(-.)'" \ + "*::archive file:_files -g '(#i)*.(7z|Z|apk|aar|bz2|cab|cpio|deb|ear|gz|ipa|ipsw|jar|lrz|lz4|lzma|rar|rpm|sublime-package|tar|tar.bz2|tar.gz|tar.lrz|tar.lz|tar.lz4|tar.xz|tar.zma|tar.zst|tbz|tbz2|tgz|tlz|txz|tzst|war|whl|xpi|xz|zip|zst)(-.)'" \ && return 0 diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh index e390e2dcc..1112dd52f 100644 --- a/plugins/extract/extract.plugin.zsh +++ b/plugins/extract/extract.plugin.zsh @@ -1,82 +1,85 @@ alias x=extract extract() { - local remove_archive - local success - local extract_dir + setopt localoptions noautopushd - if (( $# == 0 )); then - cat <<-'EOF' >&2 - Usage: extract [-option] [file ...] + if (( $# == 0 )); then + cat >&2 <<'EOF' +Usage: extract [-option] [file ...] - Options: - -r, --remove Remove archive after unpacking. - EOF - fi +Options: + -r, --remove Remove archive after unpacking. +EOF + fi - remove_archive=1 - if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then - remove_archive=0 - shift - fi + local remove_archive=1 + if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then + remove_archive=0 + shift + fi - while (( $# > 0 )); do - if [[ ! -f "$1" ]]; then - echo "extract: '$1' is not a valid file" >&2 - shift - continue - fi + local pwd="$PWD" + while (( $# > 0 )); do + if [[ ! -f "$1" ]]; then + echo "extract: '$1' is not a valid file" >&2 + shift + continue + fi - success=0 - extract_dir="${1:t:r}" - case "${1:l}" in - (*.tar.gz|*.tgz) (( $+commands[pigz] )) && { pigz -dc "$1" | tar xv } || tar zxvf "$1" ;; - (*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;; - (*.tar.xz|*.txz) - tar --xz --help &> /dev/null \ - && tar --xz -xvf "$1" \ - || xzcat "$1" | tar xvf - ;; - (*.tar.zma|*.tlz) - tar --lzma --help &> /dev/null \ - && tar --lzma -xvf "$1" \ - || lzcat "$1" | tar xvf - ;; - (*.tar.zst|*.tzst) - tar --zstd --help &> /dev/null \ - && tar --zstd -xvf "$1" \ - || zstdcat "$1" | tar xvf - ;; - (*.tar) tar xvf "$1" ;; - (*.tar.lz) (( $+commands[lzip] )) && tar xvf "$1" ;; - (*.tar.lz4) lz4 -c -d "$1" | tar xvf - ;; - (*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$1" ;; - (*.gz) (( $+commands[pigz] )) && pigz -dk "$1" || gunzip -k "$1" ;; - (*.bz2) bunzip2 "$1" ;; - (*.xz) unxz "$1" ;; - (*.lrz) (( $+commands[lrunzip] )) && lrunzip "$1" ;; - (*.lz4) lz4 -d "$1" ;; - (*.lzma) unlzma "$1" ;; - (*.z) uncompress "$1" ;; - (*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl) unzip "$1" -d $extract_dir ;; - (*.rar) unrar x -ad "$1" ;; - (*.rpm) mkdir "$extract_dir" && cd "$extract_dir" && rpm2cpio "../$1" | cpio --quiet -id && cd .. ;; - (*.7z) 7za x "$1" ;; - (*.deb) - mkdir -p "$extract_dir/control" - mkdir -p "$extract_dir/data" - cd "$extract_dir"; ar vx "../${1}" > /dev/null - cd control; tar xzvf ../control.tar.gz - cd ../data; extract ../data.tar.* - cd ..; rm *.tar.* debian-binary - cd .. - ;; - (*.zst) unzstd "$1" ;; - (*) - echo "extract: '$1' cannot be extracted" >&2 - success=1 - ;; - esac + local success=0 + local extract_dir="${1:t:r}" + local file="$1" full_path="${1:A}" + case "${file:l}" in + (*.tar.gz|*.tgz) (( $+commands[pigz] )) && { pigz -dc "$file" | tar xv } || tar zxvf "$file" ;; + (*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$file" ;; + (*.tar.xz|*.txz) + tar --xz --help &> /dev/null \ + && tar --xz -xvf "$file" \ + || xzcat "$file" | tar xvf - ;; + (*.tar.zma|*.tlz) + tar --lzma --help &> /dev/null \ + && tar --lzma -xvf "$file" \ + || lzcat "$file" | tar xvf - ;; + (*.tar.zst|*.tzst) + tar --zstd --help &> /dev/null \ + && tar --zstd -xvf "$file" \ + || zstdcat "$file" | tar xvf - ;; + (*.tar) tar xvf "$file" ;; + (*.tar.lz) (( $+commands[lzip] )) && tar xvf "$file" ;; + (*.tar.lz4) lz4 -c -d "$file" | tar xvf - ;; + (*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$file" ;; + (*.gz) (( $+commands[pigz] )) && pigz -dk "$file" || gunzip -k "$file" ;; + (*.bz2) bunzip2 "$file" ;; + (*.xz) unxz "$file" ;; + (*.lrz) (( $+commands[lrunzip] )) && lrunzip "$file" ;; + (*.lz4) lz4 -d "$file" ;; + (*.lzma) unlzma "$file" ;; + (*.z) uncompress "$file" ;; + (*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl) unzip "$file" -d "$extract_dir" ;; + (*.rar) unrar x -ad "$file" ;; + (*.rpm) + command mkdir -p "$extract_dir" && builtin cd -q "$extract_dir" \ + && rpm2cpio "$full_path" | cpio --quiet -id ;; + (*.7z) 7za x "$file" ;; + (*.deb) + command mkdir -p "$extract_dir/control" "$extract_dir/data" + builtin cd -q "$extract_dir"; ar vx "$full_path" > /dev/null + builtin cd -q control; extract ../control.tar.* + builtin cd -q ../data; extract ../data.tar.* + builtin cd -q ..; command rm *.tar.* debian-binary ;; + (*.zst) unzstd "$file" ;; + (*.cab) cabextract -d "$extract_dir" "$file" ;; + (*.cpio) cpio -idmvF "$file" ;; + (*) + echo "extract: '$file' cannot be extracted" >&2 + success=1 ;; + esac - (( success = $success > 0 ? $success : $? )) - (( $success == 0 )) && (( $remove_archive == 0 )) && rm "$1" - shift - done + (( success = success > 0 ? success : $? )) + (( success == 0 && remove_archive == 0 )) && rm "$full_path" + shift + + # Go back to original working directory in case we ran cd previously + builtin cd -q "$pwd" + done } diff --git a/plugins/fedora/README.md b/plugins/fedora/README.md deleted file mode 100644 index 85d8d7dea..000000000 --- a/plugins/fedora/README.md +++ /dev/null @@ -1 +0,0 @@ -The fedora plugin is deprecated. Use the [dnf plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/dnf) instead. diff --git a/plugins/fedora/fedora.plugin.zsh b/plugins/fedora/fedora.plugin.zsh deleted file mode 100644 index 226506c05..000000000 --- a/plugins/fedora/fedora.plugin.zsh +++ /dev/null @@ -1,3 +0,0 @@ -print -P "%F{yellow}The 'fedora' plugin is deprecated. Use the '%Udnf%u' plugin instead.%f" - -source "$ZSH/plugins/dnf/dnf.plugin.zsh" diff --git a/plugins/fnm/.gitignore b/plugins/fnm/.gitignore new file mode 100644 index 000000000..0b2bc9ab7 --- /dev/null +++ b/plugins/fnm/.gitignore @@ -0,0 +1,2 @@ +_fnm + diff --git a/plugins/fnm/README.md b/plugins/fnm/README.md new file mode 100644 index 000000000..00fab5cd4 --- /dev/null +++ b/plugins/fnm/README.md @@ -0,0 +1,9 @@ +# fnm plugin + +This plugin adds autocompletion for [fnm](https://github.com/Schniz/fnm) - a Node.js version manager. + +To use it, add `fnm` to the plugins array in your zshrc file: + +```zsh +plugins=(... fnm) +``` diff --git a/plugins/fnm/fnm.plugin.zsh b/plugins/fnm/fnm.plugin.zsh new file mode 100644 index 000000000..5ce558dcb --- /dev/null +++ b/plugins/fnm/fnm.plugin.zsh @@ -0,0 +1,12 @@ +# COMPLETION FUNCTION +if (( $+commands[fnm] )); then + if [[ ! -f $ZSH_CACHE_DIR/fnm_version ]] \ + || [[ "$(fnm --version)" != "$(< "$ZSH_CACHE_DIR/fnm_version")" ]] \ + || [[ ! -f $ZSH/plugins/fnm/_fnm ]]; then + fnm completions --shell=zsh > $ZSH/plugins/fnm/_fnm + fnm --version > $ZSH_CACHE_DIR/fnm_version + fi + autoload -Uz _fnm + _comps[fnm]=_fnm +fi + diff --git a/plugins/git/README.md b/plugins/git/README.md index e00f4cf92..522257d2d 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -23,7 +23,7 @@ plugins=(... git) | gb | git branch | | gba | git branch -a | | gbd | git branch -d | -| gbda | git branch --no-color --merged \| command grep -vE "^(\+\|\*\|\s*($(git_main_branch)\|development\|develop\|devel\|dev)\s*$)" \| command xargs -n 1 git branch -d | +| gbda | git branch --no-color --merged \| command grep -vE "^(\+\|\*\|\s*($(git_main_branch)\|$(git_develop_branch))\s*$)" \| command xargs -n 1 git branch -d | | gbD | git branch -D | | gbl | git blame -b -w | | gbnm | git branch --no-merged | @@ -49,8 +49,8 @@ plugins=(... git) | gcl | git clone --recurse-submodules | | gclean | git clean -id | | gpristine | git reset --hard && git clean -dffx | -| gcm | git checkout $(git_main_branch) | -| gcd | git checkout develop | +| gcm | git checkout $(git_main_branch) | +| gcd | git checkout $(git_develop_branch) | | gcmsg | git commit -m | | gco | git checkout | | gcor | git checkout --recurse-submodules | @@ -88,7 +88,7 @@ plugins=(... git) | 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 $(git_main_branch):svntrunk | +| git-svn-dcommit-push | git svn dcommit && git push github $(git_main_branch):svntrunk | | gk | gitk --all --branches | | gke | gitk --all $(git log -g --pretty=%h) | | gl | git pull | @@ -107,10 +107,10 @@ plugins=(... git) | gloga | git log --oneline --decorate --graph --all | | glp | git log --pretty=\<format\> | | gm | git merge | -| gmom | git merge origin/$(git_main_branch) | +| gmom | git merge origin/$(git_main_branch) | | gmt | git mergetool --no-prompt | | gmtvim | git mergetool --no-prompt --tool=vimdiff | -| gmum | git merge upstream/$(git_main_branch) | +| gmum | git merge upstream/$(git_main_branch) | | gma | git merge --abort | | gp | git push | | gpd | git push --dry-run | @@ -125,10 +125,10 @@ plugins=(... git) | grb | git rebase | | grba | git rebase --abort | | grbc | git rebase --continue | -| grbd | git rebase develop | +| grbd | git rebase $(git_develop_branch) | | grbi | git rebase -i | -| grbm | git rebase $(git_main_branch) | -| grbo | git rebase --onto | +| grbm | git rebase $(git_main_branch) | +| grbo | git rebase --onto | | grbs | git rebase --skip | | grev | git revert | | grh | git reset | @@ -176,7 +176,7 @@ plugins=(... git) | gupv | git pull --rebase -v | | gupa | git pull --rebase --autostash | | gupav | git pull --rebase --autostash -v | -| glum | git pull upstream $(git_main_branch) | +| glum | git pull upstream $(git_main_branch) | | 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]" | | gam | git am | @@ -214,13 +214,14 @@ These are aliases that have been removed, renamed, or otherwise modified in a wa ### Current -| 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 | -| git_main_branch | Returns the name of the main branch: `main` if it exists, `master` otherwise | +| 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 | +| git_main_branch | Returns the name of the main branch: `main` if it exists, `master` otherwise | +| git_develop_branch | Returns the name of the develop branch: `dev`, `devel`, `development` if they exist, `develop` otherwise | ### Work in Progress (WIP) diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 2a7c7290d..3cd558692 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -42,6 +42,19 @@ function git_main_branch() { echo master } +# Check for develop and similarly named branches +function git_develop_branch() { + command git rev-parse --git-dir &>/dev/null || return + local branch + for branch in dev devel development; do + if command git show-ref -q --verify refs/heads/$branch; then + echo $branch + return + fi + done + echo develop +} + # # Aliases # (sorted alphabetically) @@ -60,7 +73,7 @@ alias gapt='git apply --3way' alias gb='git branch' alias gba='git branch -a' alias gbd='git branch -d' -alias gbda='git branch --no-color --merged | command grep -vE "^(\+|\*|\s*($(git_main_branch)|development|develop|devel|dev)\s*$)" | command xargs -n 1 git branch -d' +alias gbda='git branch --no-color --merged | command grep -vE "^(\+|\*|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs -n 1 git branch -d' alias gbD='git branch -D' alias gbl='git blame -b -w' alias gbnm='git branch --no-merged' @@ -88,7 +101,7 @@ alias gcl='git clone --recurse-submodules' alias gclean='git clean -id' alias gpristine='git reset --hard && git clean -dffx' alias gcm='git checkout $(git_main_branch)' -alias gcd='git checkout develop' +alias gcd='git checkout $(git_develop_branch)' alias gcmsg='git commit -m' alias gco='git checkout' alias gcor='git checkout --recurse-submodules' @@ -227,7 +240,7 @@ alias gra='git remote add' alias grb='git rebase' alias grba='git rebase --abort' alias grbc='git rebase --continue' -alias grbd='git rebase develop' +alias grbd='git rebase $(git_develop_branch)' alias grbi='git rebase -i' alias grbm='git rebase $(git_main_branch)' alias grbo='git rebase --onto' diff --git a/plugins/github/README.md b/plugins/github/README.md index 70b863f64..af2b8a4e7 100644 --- a/plugins/github/README.md +++ b/plugins/github/README.md @@ -2,8 +2,8 @@ This plugin supports working with GitHub from the command line. It provides a few things: -* Sets up the `hub` wrapper and completions for the `git` command if you have `hub` installed. -* Completion for the `github` Ruby gem. +* Sets up the `hub` wrapper and completions for the `git` command if you have [`hub`](https://github.com/github/hub) installed. +* Completion for the [`github` Ruby gem](https://github.com/defunkt/github-gem). * Convenience functions for working with repos and URLs. ### Functions diff --git a/plugins/gnu-utils/gnu-utils.plugin.zsh b/plugins/gnu-utils/gnu-utils.plugin.zsh index 23e00c295..539e7fe4d 100644 --- a/plugins/gnu-utils/gnu-utils.plugin.zsh +++ b/plugins/gnu-utils/gnu-utils.plugin.zsh @@ -36,7 +36,7 @@ __gnu_utils() { gcmds+=('gfind' 'gxargs' 'glocate') # Not part of either coreutils or findutils, installed separately. - gcmds+=('gsed' 'gtar' 'gtime' 'gmake') + gcmds+=('gsed' 'gtar' 'gtime' 'gmake' 'ggrep') for gcmd in "${gcmds[@]}"; do # Do nothing if the command isn't found diff --git a/plugins/go/README.md b/plugins/go/README.md deleted file mode 100644 index bf43b9feb..000000000 --- a/plugins/go/README.md +++ /dev/null @@ -1 +0,0 @@ -The go plugin is deprecated. Use the [golang plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/golang) instead. diff --git a/plugins/go/go.plugin.zsh b/plugins/go/go.plugin.zsh deleted file mode 100644 index da7c87cfd..000000000 --- a/plugins/go/go.plugin.zsh +++ /dev/null @@ -1,3 +0,0 @@ -print -P "%F{yellow}The 'go' plugin is deprecated. Use the '%Ugolang%u' plugin instead.%f" - -source "$ZSH/plugins/golang/golang.plugin.zsh" diff --git a/plugins/invoke/README.md b/plugins/invoke/README.md new file mode 100644 index 000000000..3f4b88078 --- /dev/null +++ b/plugins/invoke/README.md @@ -0,0 +1,10 @@ +# Invoke plugin + +This plugin adds completion for [invoke](https://github.com/pyinvoke/invoke). + +To use it, add `invoke` to the plugins array in your `~/.zshrc` file: + +```zsh +plugins=(... invoke) +``` + diff --git a/plugins/invoke/invoke.plugin.zsh b/plugins/invoke/invoke.plugin.zsh new file mode 100644 index 000000000..8c807de02 --- /dev/null +++ b/plugins/invoke/invoke.plugin.zsh @@ -0,0 +1,5 @@ +# Autocompletion for invoke. +# +if [ $commands[invoke] ]; then + source <(invoke --print-completion-script=zsh) +fi diff --git a/plugins/octozen/README.md b/plugins/octozen/README.md new file mode 100644 index 000000000..2051248ca --- /dev/null +++ b/plugins/octozen/README.md @@ -0,0 +1,12 @@ +# Octozen plugin + +Displays a zen quote from GitHub's Octocat on start up. + +To use it, add `octozen` to the plugins array in your zshrc file: + +```zsh +plugins=(... octozen) +``` + +It defines a `display_octozen` function that fetches a GitHub Octocat zen quote. +NOTE: Internet connection is required (will time out if not fetched in 2 seconds). diff --git a/plugins/octozen/octozen.plugin.zsh b/plugins/octozen/octozen.plugin.zsh new file mode 100644 index 000000000..71ee550a5 --- /dev/null +++ b/plugins/octozen/octozen.plugin.zsh @@ -0,0 +1,11 @@ +# octozen plugin + +# Displays a zen quote from octocat +function display_octozen() { + curl -m 2 -fsL "https://api.github.com/octocat" + add-zsh-hook -d precmd display_octozen +} + +# Display the octocat on the first precmd, after the whole starting process has finished +autoload -Uz add-zsh-hook +add-zsh-hook precmd display_octozen diff --git a/plugins/pyenv/pyenv.plugin.zsh b/plugins/pyenv/pyenv.plugin.zsh index 82ba6ff8c..813f64b42 100644 --- a/plugins/pyenv/pyenv.plugin.zsh +++ b/plugins/pyenv/pyenv.plugin.zsh @@ -1,46 +1,71 @@ # This plugin loads pyenv into the current shell and provides prompt info via # the 'pyenv_prompt_info' function. Also loads pyenv-virtualenv if available. -# Load pyenv only if command not already available -if command -v pyenv &> /dev/null && [[ "$(uname -r)" != *icrosoft* ]]; then - FOUND_PYENV=1 +# Look for pyenv in $PATH and verify that it's not a part of pyenv-win in WSL +if ! command -v pyenv &>/dev/null; then + FOUND_PYENV=0 +elif [[ "${commands[pyenv]}" = */pyenv-win/* && "$(uname -r)" = *icrosoft* ]]; then + FOUND_PYENV=0 else - FOUND_PYENV=0 + FOUND_PYENV=1 fi +# Look for pyenv and try to load it (will only work on interactive shells) if [[ $FOUND_PYENV -ne 1 ]]; then - pyenvdirs=("$HOME/.pyenv" "/usr/local/pyenv" "/opt/pyenv" "/usr/local/opt/pyenv") - for dir in $pyenvdirs; do - if [[ -d $dir/bin ]]; then - export PATH="$PATH:$dir/bin" - FOUND_PYENV=1 - break - fi - done -fi + pyenvdirs=("$HOME/.pyenv" "/usr/local/pyenv" "/opt/pyenv" "/usr/local/opt/pyenv") + for dir in $pyenvdirs; do + if [[ -d "$dir/bin" ]]; then + FOUND_PYENV=1 + break + fi + done -if [[ $FOUND_PYENV -ne 1 ]]; then + if [[ $FOUND_PYENV -ne 1 ]]; then if (( $+commands[brew] )) && dir=$(brew --prefix pyenv 2>/dev/null); then - if [[ -d $dir/bin ]]; then - export PATH="$PATH:$dir/bin" - FOUND_PYENV=1 - fi + if [[ -d "$dir/bin" ]]; then + FOUND_PYENV=1 + fi fi + fi + + # If we found pyenv, load it but show a caveat about non-interactive shells + if [[ $FOUND_PYENV -eq 1 ]]; then + cat <<EOF +Found pyenv, but it is badly configured. pyenv might not work for +non-interactive shells (for example, when run from a script). +${bold_color} +To fix this message, add these lines to the '.profile' and '.zprofile' files +in your home directory: + +export PYENV_ROOT="${dir/#$HOME/\$HOME}" +export PATH="\$PYENV_ROOT/bin:\$PATH" +eval "\$(pyenv init --path)" +${reset_color} +For more info go to https://github.com/pyenv/pyenv/#installation. +EOF + + # Configuring in .zshrc only makes pyenv available for interactive shells + export PYENV_ROOT=$dir + export PATH="$PYENV_ROOT/bin:$PATH" + eval "$(pyenv init --path)" + fi fi if [[ $FOUND_PYENV -eq 1 ]]; then - eval "$(pyenv init - --no-rehash zsh)" - if (( $+commands[pyenv-virtualenv-init] )); then - eval "$(pyenv virtualenv-init - zsh)" - fi - function pyenv_prompt_info() { - echo "$(pyenv version-name)" - } + eval "$(pyenv init - --no-rehash zsh)" + + if (( ${+commands[pyenv-virtualenv-init]} )); then + eval "$(pyenv virtualenv-init - zsh)" + fi + + function pyenv_prompt_info() { + echo "$(pyenv version-name)" + } else - # fallback to system python - function pyenv_prompt_info() { - echo "system: $(python -V 2>&1 | cut -f 2 -d ' ')" - } + # Fall back to system python + function pyenv_prompt_info() { + echo "system: $(python -V 2>&1 | cut -f 2 -d ' ')" + } fi unset FOUND_PYENV pyenvdirs dir |