Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
kareefardi committed Aug 13, 2021
2 parents ca54076 + af6c7f3 commit 0dcc413
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 79 deletions.
77 changes: 72 additions & 5 deletions lib/cli.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function _omz {
changelog) local -a refs
refs=("${(@f)$(command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
_describe 'command' refs ;;
plugin) subcmds=('info:Get plugin information' 'list:List plugins')
plugin) subcmds=('info:Get plugin information' 'list:List plugins' 'load:Load plugin(s)')
_describe 'command' subcmds ;;
pr) subcmds=('test:Test a Pull Request' 'clean:Delete all Pull Request branches')
_describe 'command' subcmds ;;
Expand All @@ -46,10 +46,26 @@ function _omz {
esac
elif (( CURRENT == 4 )); then
case "$words[2]::$words[3]" in
plugin::info) compadd "$ZSH"/plugins/*/README.md(.N:h:t) \
"$ZSH_CUSTOM"/plugins/*/README.md(.N:h:t) ;;
theme::use) compadd "$ZSH"/themes/*.zsh-theme(.N:t:r) \
"$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::) ;;
plugin::(info|load))
local -aU plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(.N:h:t))
_describe 'plugin' plugins ;;
theme::use)
local -aU themes=("$ZSH"/themes/*.zsh-theme(.N:t:r) "$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::))
_describe 'theme' themes ;;
esac
elif (( CURRENT > 4 )); then
case "$words[2]::$words[3]" in
plugin::load)
local -aU plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(.N:h:t))

# Remove plugins already passed as arguments
# NOTE: $(( CURRENT - 1 )) is the last plugin argument completely passed, i.e. that which
# has a space after them. This is to avoid removing plugins partially passed, which makes
# the completion not add a space after the completed plugin.
local -a args=(${words[4,$(( CURRENT - 1))]})
plugins=(${plugins:|args})

_describe 'plugin' plugins ;;
esac
fi

Expand Down Expand Up @@ -147,6 +163,7 @@ Available commands:
info <plugin> Get information of a plugin
list List all available Oh My Zsh plugins
load <plugin> Load plugin(s)
EOF
return 1
Expand Down Expand Up @@ -205,6 +222,56 @@ function _omz::plugin::list {
fi
}

function _omz::plugin::load {
if [[ -z "$1" ]]; then
echo >&2 "Usage: omz plugin load <plugin> [...]"
return 1
fi

local plugins=("$@")
local plugin base has_completion=0

for plugin in $plugins; do
if [[ -d "$ZSH_CUSTOM/plugins/$plugin" ]]; then
base="$ZSH_CUSTOM/plugins/$plugin"
elif [[ -d "$ZSH/plugins/$plugin" ]]; then
base="$ZSH/plugins/$plugin"
else
_omz::log warn "plugin '$plugin' not found"
continue
fi

# Check if its a valid plugin
if [[ ! -f "$base/_$plugin" && ! -f "$base/$plugin.plugin.zsh" ]]; then
_omz::log warn "'$plugin' is not a valid plugin"
continue
# It it is a valid plugin, add its directory to $fpath unless it is already there
elif (( ! ${fpath[(Ie)$base]} )); then
fpath=("$base" $fpath)
fi

# Check if it has completion to reload compinit
if [[ -f "$base/_$plugin" ]]; then
has_completion=1
fi

# Load the plugin
if [[ -f "$base/$plugin.plugin.zsh" ]]; then
source "$base/$plugin.plugin.zsh"
fi
done

# If we have completion, we need to reload the completion
# We pass -D to avoid generating a new dump file, which would overwrite our
# current one for the next session (and we don't want that because we're not
# actually enabling the plugins for the next session).
# Note that we still have to pass -d "$_comp_dumpfile", so that compinit
# doesn't use the default zcompdump location (${ZDOTDIR:-$HOME}/.zcompdump).
if (( has_completion )); then
compinit -D -d "$_comp_dumpfile"
fi
}

function _omz::pr {
(( $# > 0 && $+functions[_omz::pr::$1] )) || {
cat <<EOF
Expand Down
34 changes: 19 additions & 15 deletions lib/functions.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ function upgrade_oh_my_zsh() {
omz update
}

function takedir() {
mkdir -p $@ && cd ${@:$#}
}

function open_command() {
local open_cmd

Expand All @@ -37,27 +33,35 @@ function open_command() {
${=open_cmd} "$@" &>/dev/null
}

# take functions

# mkcd is equivalent to takedir
function mkcd takedir() {
mkdir -p $@ && cd ${@:$#}
}

function takeurl() {
data=$(mktemp)
curl -L $1 > $data
tar xf $data
thedir=$(tar tf $data | head -1)
rm $data
cd $thedir
local data thedir
data="$(mktemp)"
curl -L "$1" > "$data"
tar xf "$data"
thedir="$(tar tf "$data" | head -1)"
rm "$data"
cd "$thedir"
}

function takegit() {
git clone $1
cd $(basename ${1%%.git})
git clone "$1"
cd "$(basename ${1%%.git})"
}

function take() {
if [[ $1 =~ ^(https?|ftp).*\.tar\.(gz|bz2|xz)$ ]]; then
takeurl $1
takeurl "$1"
elif [[ $1 =~ ^([A-Za-z0-9]\+@|https?|git|ssh|ftps?|rsync).*\.git/?$ ]]; then
takegit $1
takegit "$1"
else
takedir $1
takedir "$@"
fi
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/ag/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 0 additions & 26 deletions plugins/cloudapp/README.md

This file was deleted.

4 changes: 0 additions & 4 deletions plugins/cloudapp/cloudapp.plugin.zsh

This file was deleted.

1 change: 0 additions & 1 deletion plugins/fedora/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions plugins/fedora/fedora.plugin.zsh

This file was deleted.

35 changes: 18 additions & 17 deletions plugins/git/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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 |
Expand Down Expand Up @@ -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 |
Expand All @@ -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 |
Expand All @@ -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 |
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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)

Expand Down
19 changes: 16 additions & 3 deletions plugins/git/git.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
1 change: 0 additions & 1 deletion plugins/go/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions plugins/go/go.plugin.zsh

This file was deleted.

0 comments on commit 0dcc413

Please sign in to comment.