This commit is contained in:
abc 2023-09-18 11:12:08 +08:00
commit ea8b5ffe3b
45 changed files with 1207 additions and 607 deletions

View file

@ -51,5 +51,4 @@ jobs:
run: | run: |
cp tools/install.sh .github/workflows/installer/install.sh cp tools/install.sh .github/workflows/installer/install.sh
cd .github/workflows/installer cd .github/workflows/installer
vc link --yes -t ${{ secrets.VERCEL_TOKEN }}
vc deploy --prod -t ${{ secrets.VERCEL_TOKEN }} vc deploy --prod -t ${{ secrets.VERCEL_TOKEN }}

View file

@ -100,8 +100,8 @@ function detect-clipboard() {
fi fi
} }
# Detect at startup. A non-zero exit here indicates that the dummy clipboards were set, function clipcopy clippaste {
# which is not really an error. If the user calls them, they will attempt to redetect unfunction clipcopy clippaste
# (for example, perhaps the user has now installed xclip) and then either print an error detect-clipboard || true # let one retry
# or proceed successfully. "$0" "$@"
detect-clipboard || true }

View file

@ -17,7 +17,7 @@ function title {
: ${2=$1} : ${2=$1}
case "$TERM" in case "$TERM" in
cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*|foot|contour*) cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*|foot*|contour*)
print -Pn "\e]2;${2:q}\a" # set window name print -Pn "\e]2;${2:q}\a" # set window name
print -Pn "\e]1;${1:q}\a" # set tab name print -Pn "\e]1;${1:q}\a" # set tab name
;; ;;

View file

@ -1,14 +1,14 @@
# ANSI formatting function (\033[<code>m)
# 0: reset, 1: bold, 4: underline, 22: no bold, 24: no underline, 31: red, 33: yellow
omz_f() {
[ $# -gt 0 ] || return
IFS=";" printf "\033[%sm" $*
}
# If stdout is not a terminal ignore all formatting
[ -t 1 ] || omz_f() { :; }
# Protect against non-zsh execution of Oh My Zsh (use POSIX syntax here) # Protect against non-zsh execution of Oh My Zsh (use POSIX syntax here)
[ -n "$ZSH_VERSION" ] || { [ -n "$ZSH_VERSION" ] || {
# ANSI formatting function (\033[<code>m)
# 0: reset, 1: bold, 4: underline, 22: no bold, 24: no underline, 31: red, 33: yellow
omz_f() {
[ $# -gt 0 ] || return
IFS=";" printf "\033[%sm" $*
}
# If stdout is not a terminal ignore all formatting
[ -t 1 ] || omz_f() { :; }
omz_ptree() { omz_ptree() {
# Get process tree of the current process # Get process tree of the current process
pid=$$; pids="$pid" pid=$$; pids="$pid"
@ -38,6 +38,15 @@
return 1 return 1
} }
# Check if in emulation mode, if so early return
# https://github.com/ohmyzsh/ohmyzsh/issues/11686
[[ "$(emulate)" = zsh ]] || {
printf "$(omz_f 1 31)Error:$(omz_f 22) Oh My Zsh can't be loaded in \`$(emulate)\` emulation mode.$(omz_f 0)\n" >&2
return 1
}
unset -f omz_f
# If ZSH is not defined, use the current script's directory. # If ZSH is not defined, use the current script's directory.
[[ -z "$ZSH" ]] && export ZSH="${${(%):-%x}:a:h}" [[ -z "$ZSH" ]] && export ZSH="${${(%):-%x}:a:h}"
@ -187,12 +196,12 @@ _omz_source() {
fi fi
} }
# Load all of the config files in ~/oh-my-zsh that end in .zsh # Load all of the lib files in ~/oh-my-zsh/lib that end in .zsh
# TIP: Add files you don't want in git to .gitignore # TIP: Add files you don't want in git to .gitignore
for config_file ("$ZSH"/lib/*.zsh); do for lib_file ("$ZSH"/lib/*.zsh); do
_omz_source "lib/${config_file:t}" _omz_source "lib/${lib_file:t}"
done done
unset custom_config_file unset lib_file
# Load all of the plugins that were defined in ~/.zshrc # Load all of the plugins that were defined in ~/.zshrc
for plugin ($plugins); do for plugin ($plugins); do

View file

@ -0,0 +1,9 @@
tap: false
directories:
tests: tests
output: tests/_output
support: tests/_support
time_limit: 0
fail_fast: false
allow_risky: false
verbose: true

View file

@ -2,45 +2,32 @@
This plugin searches the defined aliases and outputs any that match the command inputted. This makes learning new aliases easier. This plugin searches the defined aliases and outputs any that match the command inputted. This makes learning new aliases easier.
## Usage
To use it, add `alias-finder` to the `plugins` array of your zshrc file: To use it, add `alias-finder` to the `plugins` array of your zshrc file:
``` ```
plugins=(... alias-finder) plugins=(... alias-finder)
``` ```
## Usage To enable it for every single command, set zstyle in your `~/.zshrc`.
To see if there is an alias defined for the command, pass it as an argument to `alias-finder`. This can also run automatically before each command you input - add `ZSH_ALIAS_FINDER_AUTOMATIC=true` to your zshrc if you want this.
## Options ```zsh
# ~/.zshrc
zstyle ':omz:plugins:alias-finder' autoload yes # disabled by default
zstyle ':omz:plugins:alias-finder' longer yes # disabled by default
zstyle ':omz:plugins:alias-finder' exact yes # disabled by default
zstyle ':omz:plugins:alias-finder' cheaper yes # disabled by default
```
As you can see, options are also available with zstyle.
### Options
> In order to clarify, let's say `alias a=abc` has source 'abc' and destination 'a'.
- Use `--longer` or `-l` to include aliases where the source is longer than the input (in other words, the source could contain the whole input).
- Use `--exact` or `-e` to avoid aliases where the source is shorter than the input (in other words, the source must be the same with the input).
- Use `--cheaper` or `-c` to avoid aliases where the destination is longer than the input (in other words, the destination must be the shorter than the input).
- Use `--longer` or `-l` to allow the aliases to be longer than the input (match aliases if they contain the input).
- Use `--exact` or `-e` to avoid matching aliases that are shorter than the input.
## Examples
```
$ alias-finder "git pull"
gl='git pull'
g=git
```
```
$ alias-finder "web_search google oh my zsh"
google='web_search google'
```
```
$ alias-finder "git commit -v"
gc="git commit -v"
g=git
```
```
$ alias-finder -e "git commit -v"
gc='git commit -v'
```
```
$ alias-finder -l "git commit -v"
gc='git commit -v'
'gc!'='git commit -v --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'
'gcn!'='git commit -v --no-edit --amend'
```

View file

@ -1,44 +1,59 @@
alias-finder() { alias-finder() {
local cmd="" exact="" longer="" wordStart="" wordEnd="" multiWordEnd="" local cmd=" " exact="" longer="" cheaper="" wordEnd="'{0,1}$" finder="" filter=""
for i in $@; do
case $i in # build command and options
for c in "$@"; do
case $c in
# TODO: Remove backward compatibility (other than zstyle form)
# set options if exist
-e|--exact) exact=true;; -e|--exact) exact=true;;
-l|--longer) longer=true;; -l|--longer) longer=true;;
*) -c|--cheaper) cheaper=true;;
if [[ -z $cmd ]]; then # concatenate cmd
cmd=$i *) cmd="$cmd$c " ;;
else
cmd="$cmd $i"
fi
;;
esac esac
done done
cmd=$(sed 's/[].\|$(){}?+*^[]/\\&/g' <<< $cmd) # adds escaping for grep
if (( $(wc -l <<< $cmd) == 1 )); then zstyle -t ':omz:plugins:alias-finder' longer && longer=true
while [[ $cmd != "" ]]; do zstyle -t ':omz:plugins:alias-finder' exact && exact=true
if [[ $longer = true ]]; then zstyle -t ':omz:plugins:alias-finder' cheaper && cheaper=true
wordStart="'{0,1}"
else # format cmd for grep
wordEnd="$" ## - replace newlines with spaces
multiWordEnd="'$" ## - trim both ends
fi ## - replace multiple spaces with one space
if [[ $cmd == *" "* ]]; then ## - add escaping character to special characters
local finder="'$cmd$multiWordEnd" cmd=$(echo -n "$cmd" | tr '\n' ' ' | xargs | tr -s '[:space:]' | sed 's/[].\|$(){}?+*^[]/\\&/g')
else
local finder=$wordStart$cmd$wordEnd if [[ $longer == true ]]; then
fi wordEnd="" # remove wordEnd to find longer aliases
alias | grep -E "=$finder"
if [[ $exact = true || $longer = true ]]; then
break
else
cmd=$(sed -E 's/ {0,1}[^ ]*$//' <<< $cmd) # removes last word
fi
done
fi fi
# find with alias and grep, removing last word each time until no more words
while [[ $cmd != "" ]]; do
finder="'{0,1}$cmd$wordEnd"
# make filter to find only shorter results than current cmd
if [[ $cheaper == true ]]; then
cmdLen=$(echo -n "$cmd" | wc -c)
filter="^'{0,1}.{0,$((cmdLen - 1))}="
fi
alias | grep -E "$filter" | grep -E "=$finder"
if [[ $exact == true ]]; then
break # because exact case is only one
elif [[ $longer = true ]]; then
break # because above grep command already found every longer aliases during first cycle
fi
cmd=$(sed -E 's/ {0,}[^ ]*$//' <<< "$cmd") # remove last word
done
} }
preexec_alias-finder() { preexec_alias-finder() {
if [[ $ZSH_ALIAS_FINDER_AUTOMATIC = true ]]; then # TODO: Remove backward compatibility (other than zstyle form)
zstyle -t ':omz:plugins:alias-finder' autoload && alias-finder $1 || if [[ $ZSH_ALIAS_FINDER_AUTOMATIC = true ]]; then
alias-finder $1 alias-finder $1
fi fi
} }

View file

@ -0,0 +1,2 @@
#!/usr/bin/env zsh
# Write your bootstrap code here

View file

@ -0,0 +1,107 @@
#!/usr/bin/env zunit
@setup {
load ../alias-finder.plugin.zsh
set_git_aliases() {
unalias -a # all
alias g="git"
alias gc="git commit"
alias gcv="git commit -v"
alias gcvs="git commit -v -S"
}
}
@test 'find aliases that contain input' {
set_git_aliases
run alias-finder "git"
assert "${#lines[@]}" equals 1
assert "${lines[1]}" same_as "g=git"
}
@test 'find aliases that contain input with whitespaces at ends' {
set_git_aliases
run alias-finder " git "
assert "${#lines[@]}" equals 1
assert "${lines[1]}" same_as "g=git"
}
@test 'find aliases that contain multiple words' {
set_git_aliases
run alias-finder "git commit -v"
assert "${#lines[@]}" equals 3
assert "${lines[1]}" same_as "gcv='git commit -v'"
assert "${lines[2]}" same_as "gc='git commit'"
assert "${lines[3]}" same_as "g=git"
}
@test 'find alias that is the same with input when --exact option is set' {
set_git_aliases
run alias-finder -e "git"
assert "${#lines[@]}" equals 1
assert "${lines[1]}" same_as "g=git"
}
@test 'find alias that is the same with multiple words input when --exact option is set' {
set_git_aliases
run alias-finder -e "git commit -v"
assert "${#lines[@]}" equals 1
assert "${lines[1]}" same_as "gcv='git commit -v'"
}
@test 'find alias that is the same with or longer than input when --longer option is set' {
set_git_aliases
run alias-finder -l "git"
assert "${#lines[@]}" equals 4
assert "${lines[1]}" same_as "g=git"
assert "${lines[2]}" same_as "gc='git commit'"
assert "${lines[3]}" same_as "gcv='git commit -v'"
assert "${lines[4]}" same_as "gcvs='git commit -v -S'"
}
@test 'find alias that is the same with or longer than multiple words input when --longer option is set' {
set_git_aliases
run alias-finder -l "git commit -v"
assert "${#lines[@]}" equals 2
assert "${lines[1]}" same_as "gcv='git commit -v'"
assert "${lines[2]}" same_as "gcvs='git commit -v -S'"
}
@test 'find aliases including expensive (longer) than input' {
set_git_aliases
alias expensiveCommands="git commit"
run alias-finder "git commit -v"
assert "${#lines[@]}" equals 4
assert "${lines[1]}" same_as "gcv='git commit -v'"
assert "${lines[2]}" same_as "expensiveCommands='git commit'"
assert "${lines[3]}" same_as "gc='git commit'"
assert "${lines[4]}" same_as "g=git"
}
@test 'find aliases excluding expensive (longer) than input when --cheap option is set' {
set_git_aliases
alias expensiveCommands="git commit"
run alias-finder -c "git commit -v"
assert "${#lines[@]}" equals 3
assert "${lines[1]}" same_as "gcv='git commit -v'"
assert "${lines[2]}" same_as "gc='git commit'"
assert "${lines[3]}" same_as "g=git"
}

View file

@ -25,4 +25,4 @@ Requirements: Python needs to be installed.
- `als --groups`: show only group names - `als --groups`: show only group names
![screenshot](https://cloud.githubusercontent.com/assets/3602957/11581913/cb54fb8a-9a82-11e5-846b-5a67f67ad9ad.png) ![screenshot](https://github.com/ohmyzsh/ohmyzsh/assets/66907184/5bfa00ea-5fc3-4e97-8b22-2f74f6b948c7)

View file

@ -13,6 +13,10 @@
# Author: Avneet Singh (kalsi-avneet) # # Author: Avneet Singh (kalsi-avneet) #
# Modified to add support for Android # # Modified to add support for Android #
########################################### ###########################################
# Author: Not Pua (im-notpua) #
# Modified to add support for OpenBSD #
###########################################
if [[ "$OSTYPE" = darwin* ]]; then if [[ "$OSTYPE" = darwin* ]]; then
function battery_is_charging() { function battery_is_charging() {
@ -139,6 +143,46 @@ elif [[ "$OSTYPE" = linux-android ]] && (( ${+commands[termux-battery-status]} )
echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}" echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}"
fi fi
} }
elif [[ "$OSTYPE" = openbsd* ]]; then
function battery_is_charging() {
[[ $(apm -b) -eq 3 ]]
}
function battery_pct() {
apm -l
}
function battery_pct_remaining() {
if ! battery_is_charging; then
battery_pct
else
echo "External Power"
fi
}
function battery_time_remaining() {
local remaining_time
remaining_time=$(apm -m)
if [[ $remaining_time -ge 0 ]]; then
((hour = $remaining_time / 60 ))
((minute = $remaining_time % 60 ))
printf %02d:%02d $hour $minute
fi
}
function battery_pct_prompt() {
local battery_pct color
battery_pct=$(battery_pct_remaining)
if battery_is_charging; then
echo "∞"
else
if [[ $battery_pct -gt 50 ]]; then
color='green'
elif [[ $battery_pct -gt 20 ]]; then
color='yellow'
else
color='red'
fi
echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}"
fi
}
elif [[ "$OSTYPE" = linux* ]]; then elif [[ "$OSTYPE" = linux* ]]; then
function battery_is_charging() { function battery_is_charging() {
if (( $+commands[acpitool] )); then if (( $+commands[acpitool] )); then

View file

@ -10,10 +10,12 @@ plugins=(... brew)
## Shellenv ## Shellenv
If `brew` is not found in the PATH, this plugin will attempt to find it in common If `brew` is not found in the PATH, this plugin will attempt to find it in common locations, and execute
locations, and execute `brew shellenv` to set the environment appropriately. `brew shellenv` to set the environment appropriately. This plugin will also export
This plugin will also export `HOMEBREW_PREFIX="$(brew --prefix)"` if not previously `HOMEBREW_PREFIX="$(brew --prefix)"` if not previously defined for convenience.
defined for convenience.
In case you installed `brew` in a non-common location, you can still set `BREW_LOCATION` variable pointing to
the `brew` binary before sourcing `oh-my-zsh.sh` and it'll set up the environment.
## Aliases ## Aliases
@ -33,9 +35,9 @@ defined for convenience.
## Completion ## Completion
This plugin configures paths with Homebrew's completion functions automatically, so you don't need to do it manually. See: https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh. This plugin configures paths with Homebrew's completion functions automatically, so you don't need to do it
manually. See: https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh.
With the release of Homebrew 1.0, they decided to bundle the zsh completion as part of the With the release of Homebrew 1.0, they decided to bundle the zsh completion as part of the brew installation,
brew installation, so we no longer ship it with the brew plugin; now it only has brew so we no longer ship it with the brew plugin; now it only has brew aliases. If you find that brew completion
aliases. If you find that brew completion no longer works, make sure you have your Homebrew no longer works, make sure you have your Homebrew installation fully up to date.
installation fully up to date.

View file

@ -1,5 +1,10 @@
if (( ! $+commands[brew] )); then if (( ! $+commands[brew] )); then
if [[ -x /opt/homebrew/bin/brew ]]; then if [[ -n "$BREW_LOCATION" ]]; then
if [[ ! -x "$BREW_LOCATION" ]]; then
echo "[oh-my-zsh] $BREW_LOCATION is not executable"
return
fi
elif [[ -x /opt/homebrew/bin/brew ]]; then
BREW_LOCATION="/opt/homebrew/bin/brew" BREW_LOCATION="/opt/homebrew/bin/brew"
elif [[ -x /usr/local/bin/brew ]]; then elif [[ -x /usr/local/bin/brew ]]; then
BREW_LOCATION="/usr/local/bin/brew" BREW_LOCATION="/usr/local/bin/brew"

20
plugins/bun/README.md Normal file
View file

@ -0,0 +1,20 @@
# Bun Plugin
This plugin sets up completion for [Bun](https://bun.sh).
To use it, add `bun` to the plugins array in your zshrc file:
```zsh
plugins=(... bun)
```
This plugin does not add any aliases.
## Cache
This plugin caches the completion script and is automatically updated when the
plugin is loaded, which is usually when you start up a new terminal emulator.
The cache is stored at:
- `$ZSH_CACHE_DIR/completions/_bun_` completions script

View file

@ -0,0 +1,14 @@
# If Bun is not found, don't do the rest of the script
if (( ! $+commands[bun] )); then
return
fi
# If the completion file doesn't exist yet, we need to autoload it and
# bind it to `bun`. Otherwise, compinit will have already done that.
if [[ ! -f "$ZSH_CACHE_DIR/completions/_bun" ]]; then
typeset -g -A _comps
autoload -Uz _bun
_comps[bun]=_bun
fi
bun completions >| "$ZSH_CACHE_DIR/completions/_bun" &|

View file

@ -36,6 +36,7 @@ function colored() {
# Prefer `less` whenever available, since we specifically configured # Prefer `less` whenever available, since we specifically configured
# environment for it. # environment for it.
environment+=( PAGER="${commands[less]:-$PAGER}" ) environment+=( PAGER="${commands[less]:-$PAGER}" )
environment+=( GROFF_NO_SGR=1 )
# See ./nroff script. # See ./nroff script.
if [[ "$OSTYPE" = solaris* ]]; then if [[ "$OSTYPE" = solaris* ]]; then

View file

@ -30,6 +30,11 @@ EOF
local file="$1" full_path="${1:A}" local file="$1" full_path="${1:A}"
local extract_dir="${1:t:r}" local extract_dir="${1:t:r}"
# Remove the .tar extension if the file name is .tar.*
if [[ $extract_dir =~ '\.tar$' ]]; then
extract_dir="${extract_dir:r}"
fi
# If there's a file or directory with the same name as the archive # If there's a file or directory with the same name as the archive
# add a random string to the end of the extract directory # add a random string to the end of the extract directory
if [[ -e "$extract_dir" ]]; then if [[ -e "$extract_dir" ]]; then
@ -64,7 +69,7 @@ EOF
(*.tar.lz) (( $+commands[lzip] )) && tar xvf "$full_path" ;; (*.tar.lz) (( $+commands[lzip] )) && tar xvf "$full_path" ;;
(*.tar.lz4) lz4 -c -d "$full_path" | tar xvf - ;; (*.tar.lz4) lz4 -c -d "$full_path" | tar xvf - ;;
(*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$full_path" ;; (*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$full_path" ;;
(*.gz) (( $+commands[pigz] )) && pigz -dk "$full_path" || gunzip -k "$full_path" ;; (*.gz) (( $+commands[pigz] )) && pigz -cdk "$full_path" > "${file:t:r}" || gunzip -ck "$full_path" > "${file:t:r}" ;;
(*.bz2) bunzip2 "$full_path" ;; (*.bz2) bunzip2 "$full_path" ;;
(*.xz) unxz "$full_path" ;; (*.xz) unxz "$full_path" ;;
(*.lrz) (( $+commands[lrunzip] )) && lrunzip "$full_path" ;; (*.lrz) (( $+commands[lrunzip] )) && lrunzip "$full_path" ;;
@ -106,19 +111,19 @@ EOF
# - Y2: at most give 2 files # - Y2: at most give 2 files
local -a content local -a content
content=("${extract_dir}"/*(DNY2)) content=("${extract_dir}"/*(DNY2))
if [[ ${#content} -eq 1 && -d "${content[1]}" ]]; then if [[ ${#content} -eq 1 && -e "${content[1]}" ]]; then
# The extracted folder (${content[1]}) may have the same name as $extract_dir # The extracted file/folder (${content[1]}) may have the same name as $extract_dir
# If so, we need to rename it to avoid conflicts in a 3-step process # If so, we need to rename it to avoid conflicts in a 3-step process
# #
# 1. Move and rename the extracted folder to a temporary random name # 1. Move and rename the extracted file/folder to a temporary random name
# 2. Delete the empty folder # 2. Delete the empty folder
# 3. Rename the extracted folder to the original name # 3. Rename the extracted file/folder to the original name
if [[ "${content[1]:t}" == "$extract_dir" ]]; then if [[ "${content[1]:t}" == "$extract_dir" ]]; then
# =(:) gives /tmp/zsh<random>, with :t it gives zsh<random> # =(:) gives /tmp/zsh<random>, with :t it gives zsh<random>
local tmp_dir==(:); tmp_dir="${tmp_dir:t}" local tmp_name==(:); tmp_name="${tmp_name:t}"
command mv "${content[1]}" "$tmp_dir" \ command mv "${content[1]}" "$tmp_name" \
&& command rmdir "$extract_dir" \ && command rmdir "$extract_dir" \
&& command mv "$tmp_dir" "$extract_dir" && command mv "$tmp_name" "$extract_dir"
# Otherwise, if the extracted folder name already exists in the current # Otherwise, if the extracted folder name already exists in the current
# directory (because of a previous file / folder), keep the extract_dir # directory (because of a previous file / folder), keep the extract_dir
elif [[ ! -e "${content[1]:t}" ]]; then elif [[ ! -e "${content[1]:t}" ]]; then

View file

@ -0,0 +1,36 @@
# git-commit plugin
The git-commit plugin adds several [git aliases](https://www.git-scm.com/docs/git-config#Documentation/git-config.txt-alias) for [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/#summary) messages.
To use it, add `git-commit` to the plugins array in your zshrc file:
```zsh
plugins=(... git-commit)
```
## Syntax
```zshrc
git <type> [(-s, --scope) "<scope>"] "<message>"
```
> ⚠️ Single/Double quotes around the scope and message are required
Where `type` is one of the following:
- `build`
- `chore`
- `ci`
- `docs`
- `feat`
- `fix`
- `perf`
- `refactor`
- `revert`
- `style`
- `test`
## Examples
`git style "remove trailing whitespace"` -> `git commit -m "style: remove trailing whitespace"`
`git fix -s "router" "correct redirect link"` -> `git commit -m "fix(router): correct redirect link"`

View file

@ -0,0 +1,27 @@
function _git_commit_register {
if ! git config --global --get-all alias.$1 >/dev/null 2>&1; then
git config --global alias.$1 '!a() { if [ "$1" = "-s" ] || [ "$1" = "--scope" ]; then local scope="$2"; shift 2; git commit -m "'$1'(${scope}): ${@}"; else git commit -m "'$1': ${@}"; fi }; a'
fi
}
local -a _git_commit_aliases
_git_commit_aliases=(
'build'
'chore'
'ci'
'docs'
'feat'
'fix'
'perf'
'refactor'
'revert'
'style'
'test'
)
for _alias in "${_git_commit_aliases[@]}"; do
_git_commit_register $_alias
done
unfunction _git_commit_register
unset _alias

View file

@ -10,213 +10,216 @@ plugins=(... git)
## Aliases ## Aliases
| Alias | Command | | Alias | Command |
| :------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | :------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| g | git | | grt | cd "$(git rev-parse --show-toplevel &#124;&#124; echo .)" |
| ga | git add | | ggpnp | ggl && ggp |
| gaa | git add --all | | ggpur | ggu |
| gapa | git add --patch | | g | git |
| gau | git add --update | | ga | git add |
| gav | git add --verbose | | gaa | git add --all |
| gap | git apply | | gapa | git add --patch |
| gapt | git apply --3way | | gau | git add --update |
| gb | git branch | | gav | git add --verbose |
| gba | git branch --all | | gwip | git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]" |
| gbd | git branch --delete | | gam | git am |
| gbda | git branch --no-color --merged \| grep -vE "^([+*]\|\s*(<span>$</span>(git_main_branch)\|<span>$</span>(git_develop_branch))\s*<span>$</span>)" \| xargs git branch --delete 2>/dev/null | | gama | git am --abort |
| gbD | git branch --delete --force | | gamc | git am --continue |
| gbg | git branch -vv | grep ": gone\]" | | gamscp | git am --show-current-patch |
| gbgd | git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d | | gams | git am --skip |
| gbgD | git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D | | gap | git apply |
| gbl | git blame -b -w | | gapt | git apply --3way |
| gbnm | git branch --no-merged | | gbs | git bisect |
| gbr | git branch --remote | | gbsb | git bisect bad |
| gbs | git bisect | | gbsg | git bisect good |
| gbsb | git bisect bad | | gbsn | git bisect new |
| gbsg | git bisect good | | gbso | git bisect old |
| gbsr | git bisect reset | | gbsr | git bisect reset |
| gbss | git bisect start | | gbss | git bisect start |
| gc | git commit --verbose | | gbl | git blame -w |
| gc! | git commit --verbose --amend | | gb | git branch |
| gcn! | git commit --verbose --no-edit --amend | | gba | git branch --all |
| gca | git commit --verbose --all | | gbd | git branch --delete |
| gca! | git commit --verbose --all --amend | | gbD | git branch --delete --force |
| gcan! | git commit --verbose --all --no-edit --amend | | gbda | git branch --no-color --merged &#124; grep -vE "^([+]&#124;\s($(git_main_branch)&#124;$(git_develop_branch))\s\*$)" &#124; xargs git branch --delete 2>/dev/null |
| gcans! | git commit --verbose --all --signoff --no-edit --amend | | gbgd | LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d |
| gcam | git commit --all --message | | gbgD | LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D |
| gcas | git commit --all --signoff | | gbnm | git branch --no-merged |
| gcasm | git commit --all --signoff --message | | gbr | git branch --remote |
| gcsm | git commit --signoff --message | | ggsup | git branch --set-upstream-to=origin/$(git_current_branch) |
| gcb | git checkout -b | | gbg | LANG=C git branch -vv | grep ": gone\]" |
| gcf | git config --list | | gco | git checkout |
| gcl | git clone --recurse-submodules | | gcor | git checkout --recurse-submodules |
| gccd | git clone --recurse-submodules "<span>$</span>@" && cd "<span>$</span>(basename <span>$</span>\_ .git)" | | gcb | git checkout -b |
| gclean | git clean --interactive -d | | gcd | git checkout $(git_develop_branch) |
| gpristine | git reset --hard && git clean -dffx | | gcm | git checkout $(git_main_branch) |
| gcm | git checkout $(git_main_branch) | | gcp | git cherry-pick |
| gcd | git checkout $(git_develop_branch) | | gcpa | git cherry-pick --abort |
| gcmsg | git commit --message | | gcpc | git cherry-pick --continue |
| gco | git checkout | | gclean | git clean --interactive -d |
| gcor | git checkout --recurse-submodules | | gcl | git clone --recurse-submodules |
| gcount | git shortlog --summary -n | | gccd | git clone --recurse-submodules "$@" && cd "$(basename $\_ .git)" |
| gcp | git cherry-pick | | gcam | git commit --all --message |
| gcpa | git cherry-pick --abort | | gcas | git commit --all --signoff |
| gcpc | git cherry-pick --continue | | gcasm | git commit --all --signoff --message |
| gcs | git commit -S | | gcmsg | git commit --message |
| gcss | git commit -S -s | | gcsm | git commit --signoff --message |
| gcssm | git commit -S -s -m | | gc | git commit --verbose |
| gd | git diff | | gca | git commit --verbose --all |
| gdca | git diff --cached | | gca! | git commit --verbose --all --amend |
| gdcw | git diff --cached --word-diff | | gcan! | git commit --verbose --all --no-edit --amend |
| gdct | git describe --tags $(git rev-list --tags --max-count=1) | | gcans! | git commit --verbose --all --signoff --no-edit --amend |
| gds | git diff --staged | | gc! | git commit --verbose --amend |
| gdt | git diff-tree --no-commit-id --name-only -r | | gcn! | git commit --verbose --no-edit --amend |
| gdnolock | git diff $@ ":(exclude)package-lock.json" ":(exclude)\*.lock" | | gcs | git commit -S |
| gdup | git diff @{upstream} | | gcss | git commit -S -s |
| gdv | git diff -w $@ \| view - | | gcssm | git commit -S -s -m |
| gdw | git diff --word-diff | | gcf | git config --list |
| gf | git fetch | | gdct | git describe --tags $(git rev-list --tags --max-count=1) |
| gfa | git fetch --all --prune | | gd | git diff |
| gfg | git ls-files \| grep | | gdca | git diff --cached |
| gfo | git fetch origin | | gdcw | git diff --cached --word-diff |
| gg | git gui citool | | gds | git diff --staged |
| gga | git gui citool --amend | | gdw | git diff --word-diff |
| ggf | git push --force origin $(current_branch) | | gdv | git diff -w $@ &#124; view - |
| ggfl | git push --force-with-lease origin $(current_branch) | | gdup | git diff @{upstream} |
| ggl | git pull origin $(current_branch) | | gdnolock | git diff $@ ":(exclude)package-lock.json" ":(exclude)\*.lock" |
| ggp | git push origin $(current_branch) | | gdt | git diff-tree --no-commit-id --name-only -r |
| ggpnp | ggl && ggp | | gf | git fetch |
| ggpull | git pull origin "$(git_current_branch)" | | gfa | git fetch --all --prune |
| ggpur | ggu | | gfo | git fetch origin |
| ggpush | git push origin "$(git_current_branch)" | | gg | git gui citool |
| ggsup | git branch --set-upstream-to=origin/$(git_current_branch) | | gga | git gui citool --amend |
| ggu | git pull --rebase origin $(current_branch) | | ghh | git help |
| gpsup | git push --set-upstream origin $(git_current_branch) | | glgg | git log --graph |
| gpsupf | git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes (git version >= 2.30) | | glgga | git log --graph --decorate --all |
| gpsupf | git push --set-upstream origin $(git_current_branch) --force-with-lease (git version < 2.30) | | glgm | git log --graph --max-count=10 |
| ghh | git help | | glod | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' |
| gignore | git update-index --assume-unchanged | | glods | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short |
| gignored | git ls-files -v \| grep "^[[:lower:]]" | | glol | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' |
| git-svn-dcommit-push | git svn dcommit && git push github $(git_main_branch):svntrunk | | glola | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all |
| gk | gitk --all --branches &! | | glols | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat |
| gke | gitk --all $(git log --walk-reflogs --pretty=%h) &! | | glo | git log --oneline --decorate |
| gl | git pull | | glog | git log --oneline --decorate --graph |
| glg | git log --stat | | gloga | git log --oneline --decorate --graph --all |
| glgp | git log --stat --patch | | glp | git log --pretty=\<format> |
| glgg | git log --graph | | glg | git log --stat |
| glgga | git log --graph --decorate --all | | glgp | git log --stat --patch |
| glgm | git log --graph --max-count=10 | | gignored | git ls-files -v &#124; grep "^[[:lower:]]" |
| glo | git log --oneline --decorate | | gfg | git ls-files &#124; grep |
| glol | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' | | gm | git merge |
| glols | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat | | gma | git merge --abort |
| glod | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' | | gms | git merge --squash |
| glods | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short | | gmom | git merge origin/$(git_main_branch) |
| glola | git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all | | gmum | git merge upstream/$(git_main_branch) |
| glog | git log --oneline --decorate --graph | | gmtl | git mergetool --no-prompt |
| gloga | git log --oneline --decorate --graph --all | | gmtlvim | git mergetool --no-prompt --tool=vimdiff |
| glp | git log --pretty=\<format\> | | gl | git pull |
| gm | git merge | | gpr | git pull --rebase |
| gms | git merge --squash | | gup | git pull --rebase |
| gmom | git merge origin/$(git_main_branch) | | gupa | git pull --rebase --autostash |
| gmtl | git mergetool --no-prompt | | gupav | git pull --rebase --autostash --verbose |
| gmtlvim | git mergetool --no-prompt --tool=vimdiff | | gupv | git pull --rebase --verbose |
| gmum | git merge upstream/$(git_main_branch) | | ggu | git pull --rebase origin $(current_branch) |
| gma | git merge --abort | | gupom | git pull --rebase origin $(git_main_branch) |
| gp | git push | | gupomi | git pull --rebase=interactive origin $(git_main_branch) |
| gpd | git push --dry-run | | ggpull | git pull origin "$(git_current_branch)" |
| gpf | git push --force-with-lease --force-if-includes (git version >= 2.30) | | ggl | git pull origin $(current_branch) |
| gpf | git push --force-with-lease (git version < 2.30) | | gluc | git pull upstream $(git_current_branch) |
| gpf! | git push --force | | glum | git pull upstream $(git_main_branch) |
| gpoat | git push origin --all && git push origin --tags | | gp | git push |
| gpod | git push origin --delete | | gpd | git push --dry-run |
| gpr | git pull --rebase | | gpf! | git push --force |
| gpu | git push upstream | | ggf | git push --force origin $(current_branch) |
| gpv | git push --verbose | | gpf | git push --force-with-lease --force-if-includes (git version >= 2.30) |
| gr | git remote | | gpf | git push --force-with-lease (git version < 2.30) |
| gra | git remote add | | ggfl | git push --force-with-lease origin $(current_branch) |
| grb | git rebase | | gpsup | git push --set-upstream origin $(git_current_branch) |
| grba | git rebase --abort | | gpsupf | git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes (git version >= 2.30) |
| grbc | git rebase --continue | | gpsupf | git push --set-upstream origin $(git_current_branch) --force-with-lease (git version < 2.30) |
| grbd | git rebase $(git_develop_branch) | | gpv | git push --verbose |
| grbi | git rebase --interactive | | gpoat | git push origin --all && git push origin --tags |
| grbm | git rebase $(git_main_branch) | | gpod | git push origin --delete |
| grbom | git rebase origin/$(git_main_branch) | | ggpush | git push origin "$(git_current_branch)" |
| grbo | git rebase --onto | | ggp | git push origin $(current_branch) |
| grbs | git rebase --skip | | gpu | git push upstream |
| grev | git revert | | grb | git rebase |
| grh | git reset | | grba | git rebase --abort |
| grhh | git reset --hard | | grbc | git rebase --continue |
| groh | git reset origin/$(git_current_branch) --hard | | grbi | git rebase --interactive |
| grm | git rm | | grbo | git rebase --onto |
| grmc | git rm --cached | | grbs | git rebase --skip |
| grmv | git remote rename | | grbd | git rebase $(git_develop_branch) |
| grrm | git remote remove | | grbm | git rebase $(git_main_branch) |
| grs | git restore | | grbom | git rebase origin/$(git_main_branch) |
| grset | git remote set-url | | gr | git remote |
| grss | git restore --source | | grv | git remote --verbose |
| grst | git restore --staged | | gra | git remote add |
| grt | cd "$(git rev-parse --show-toplevel \|\| echo .)" | | grrm | git remote remove |
| gru | git reset -- | | grmv | git remote rename |
| grup | git remote update | | grset | git remote set-url |
| grv | git remote --verbose | | grup | git remote update |
| gsb | git status --short -b | | grh | git reset |
| gsd | git svn dcommit | | gru | git reset -- |
| gsh | git show | | grhh | git reset --hard |
| gsi | git submodule init | | gpristine | git reset --hard && git clean -dffx |
| gsps | git show --pretty=short --show-signature | | groh | git reset origin/$(git_current_branch) --hard |
| gsr | git svn rebase | | grs | git restore |
| gss | git status --short | | grss | git restore --source |
| gst | git status | | grst | git restore --staged |
| gsta | git stash push (git version >= 2.13) | | gunwip | git rev-list --max-count=1 --format="%s" HEAD &#124; grep -q "--wip--" && git reset HEAD~1 |
| gsta | git stash save (git version < 2.13) | | grev | git revert |
| gstaa | git stash apply | | grm | git rm |
| gstc | git stash clear | | grmc | git rm --cached |
| gstd | git stash drop | | gcount | git shortlog --summary -n |
| gstl | git stash list | | gsh | git show |
| gstp | git stash pop | | gsps | git show --pretty=short --show-signature |
| gsts | git stash show --text | | gstall | git stash --all |
| gstu | git stash --include-untracked | | gstu | git stash --include-untracked |
| gstall | git stash --all | | gstaa | git stash apply |
| gsu | git submodule update | | gstc | git stash clear |
| gsw | git switch | | gstd | git stash drop |
| gswc | git switch -c | | gstl | git stash list |
| gswm | git switch $(git_main_branch) | | gstp | git stash pop |
| gswd | git switch $(git_develop_branch) | | gsta | git stash push (git version >= 2.13) |
| gts | git tag -s | | gsta | git stash save (git version < 2.13) |
| gtv | git tag \| sort -V | | gsts | git stash show --text |
| gtl | gtl(){ git tag --sort=-v:refname -n --list ${1}\* }; noglob gtl | | gst | git status |
| gunignore | git update-index --no-assume-unchanged | | gss | git status --short |
| gunwip | git rev-list --max-count=1 --format="%s" HEAD \| grep -q "\-\-wip\-\-" && git reset HEAD~1 | | gsb | git status --short -b |
| gup | git pull --rebase | | gsi | git submodule init |
| gupv | git pull --rebase --verbose | | gsu | git submodule update |
| gupa | git pull --rebase --autostash | | gsd | git svn dcommit |
| gupav | git pull --rebase --autostash --verbose | | git-svn-dcommit-push | git svn dcommit && git push github $(git_main_branch):svntrunk |
| gupom | git pull --rebase origin $(git_main_branch) | | gsr | git svn rebase |
| gupomi | git pull --rebase=interactive origin $(git_main_branch) | | gsw | git switch |
| glum | git pull upstream $(git_main_branch) | | gswc | git switch -c |
| gluc | git pull upstream $(git_current_branch) | | gswd | git switch $(git_develop_branch) |
| gwch | git whatchanged -p --abbrev-commit --pretty=medium | | gswm | git switch $(git_main_branch) |
| gwip | git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]" | | gts | git tag -s |
| gam | git am | | gtv | git tag &#124; sort -V |
| gamc | git am --continue | | gignore | git update-index --assume-unchanged |
| gams | git am --skip | | gunignore | git update-index --no-assume-unchanged |
| gama | git am --abort | | gwch | git whatchanged -p --abbrev-commit --pretty=medium |
| gamscp | git am --show-current-patch | | gwt | git worktree |
| gwt | git worktree | | gwtls | git worktree list |
| gwtls | git worktree list | | gwtmv | git worktree move |
| gwtmv | git worktree move | | gwtrm | git worktree remove |
| gwtrm | git worktree remove | | gk | gitk --all --branches &! |
| gke | gitk --all $(git log --walk-reflogs --pretty=%h) &! |
| gtl | gtl(){ git tag --sort=-v:refname -n --list ${1}\* }; noglob gtl |
### Main branch preference ### Main branch preference
Following the recent push for removing racially-charged words from our technical vocabulary, the git plugin favors using Following the recent push for removing racially-charged words from our technical vocabulary, the git plugin
a branch name other than `master`. In this case, we favor the shorter, neutral and descriptive term `main`. This means favors using a branch name other than `master`. In this case, we favor the shorter, neutral and descriptive
that any aliases and functions that previously used `master`, will use `main` if that branch exists. We do this via the term `main`. This means that any aliases and functions that previously used `master`, will use `main` if that
function `git_main_branch`. branch exists. We do this via the function `git_main_branch`.
### Deprecated aliases ### Deprecated aliases
These are aliases that have been removed, renamed, or otherwise modified in a way that may, or may not, receive further support. 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 | | Alias | Command | Modification |
| :----- | :----------------------------------------------------- | :----------------------------------------------------- | | :----- | :----------------------------------------------------- | :----------------------------------------------------- |
@ -238,23 +241,27 @@ These are aliases that have been removed, renamed, or otherwise modified in a wa
| Command | Description | | Command | Description |
| :--------------------- | :------------------------------------------------------------------------------------------------------- | | :--------------------- | :------------------------------------------------------------------------------------------------------- |
| `grename <old> <new>` | Rename `old` branch to `new`, including in origin remote |
| current_branch | Return the name of the current branch | | 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 (lives in lib/git.zsh) |
| git_current_user_email | Returns the `user.email` config value | | git_current_user_name | Returns the `user.name` config value (lives in lib/git.zsh) |
| 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 | | git_develop_branch | Returns the name of the develop branch: `dev`, `devel`, `development` if they exist, `develop` otherwise |
| git_main_branch | Returns the name of the main branch: `main` if it exists, `master` otherwise |
| grename \<old> \<new> | Rename `old` branch to `new`, including in origin remote |
### Work in Progress (WIP) ### Work in Progress (WIP)
These features allow to pause a branch development and switch to another one (_"Work in Progress"_, or wip). When you want to go back to work, just unwip it. These features allow to pause a branch development and switch to another one (_"Work in Progress"_, or wip).
When you want to go back to work, just unwip it.
| Command | Description | | Command | Description |
| :--------------- | :---------------------------------------------- | | :--------------- | :---------------------------------------------- |
| work_in_progress | Echoes a warning if the current branch is a wip |
| gwip | Commit wip branch | | gwip | Commit wip branch |
| gunwip | Uncommit wip branch | | gunwip | Uncommit wip branch |
| gunwipall | Uncommit all recent `--wip--` commits | | gunwipall | Uncommit all recent `--wip--` commits |
| work_in_progress | Echoes a warning if the current branch is a wip |
Note that `gwip` and `gunwip` are effectivly alias, but are also documented here to group all related WIP
features.
### Deprecated functions ### Deprecated functions

View file

@ -3,7 +3,9 @@ autoload -Uz is-at-least
git_version="${${(As: :)$(git version 2>/dev/null)}[3]}" git_version="${${(As: :)$(git version 2>/dev/null)}[3]}"
# #
# Functions # Functions Current
# (sorted alphabetically by function name)
# (order should follow README)
# #
# The name of the current branch # The name of the current branch
@ -14,42 +16,6 @@ function current_branch() {
git_current_branch git_current_branch
} }
# Pretty log messages
function _git_log_prettily(){
if ! [ -z $1 ]; then
git log --pretty=$1
fi
}
compdef _git _git_log_prettily=git-log
# Warn if the current branch is a WIP
function work_in_progress() {
command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!"
}
# Similar to `gunwip` but recursive "Unwips" all recent `--wip--` commits not just the last one
function gunwipall() {
local _commit=$(git log --grep='--wip--' --invert-grep --max-count=1 --format=format:%H)
# Check if a commit without "--wip--" was found and it's not the same as HEAD
if [[ "$_commit" != "$(git rev-parse HEAD)" ]]; then
git reset $_commit || return 1
fi
}
# Check if main exists and use instead of master
function git_main_branch() {
command git rev-parse --git-dir &>/dev/null || return
local ref
for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default}; do
if command git show-ref -q --verify $ref; then
echo ${ref:t}
return
fi
done
echo master
}
# Check for develop and similarly named branches # Check for develop and similarly named branches
function git_develop_branch() { function git_develop_branch() {
command git rev-parse --git-dir &>/dev/null || return command git rev-parse --git-dir &>/dev/null || return
@ -63,289 +29,18 @@ function git_develop_branch() {
echo develop echo develop
} }
# # Check if main exists and use instead of master
# Aliases function git_main_branch() {
# (sorted alphabetically) command git rev-parse --git-dir &>/dev/null || return
# local ref
for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default}; do
alias g='git' if command git show-ref -q --verify $ref; then
echo ${ref:t}
alias ga='git add' return
alias gaa='git add --all' fi
alias gapa='git add --patch' done
alias gau='git add --update' echo master
alias gav='git add --verbose'
alias gap='git apply'
alias gapt='git apply --3way'
alias gb='git branch'
alias gba='git branch --all'
alias gbd='git branch --delete'
alias gbda='git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null'
alias gbD='git branch --delete --force'
alias gbg='git branch -vv | grep ": gone\]"'
alias gbgd='git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d'
alias gbgD='git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D'
alias gbl='git blame -b -w'
alias gbnm='git branch --no-merged'
alias gbr='git branch --remote'
alias gbs='git bisect'
alias gbsb='git bisect bad'
alias gbsg='git bisect good'
alias gbsr='git bisect reset'
alias gbss='git bisect start'
alias gc='git commit --verbose'
alias gc!='git commit --verbose --amend'
alias gcn!='git commit --verbose --no-edit --amend'
alias gca='git commit --verbose --all'
alias gca!='git commit --verbose --all --amend'
alias gcan!='git commit --verbose --all --no-edit --amend'
alias gcans!='git commit --verbose --all --signoff --no-edit --amend'
alias gcam='git commit --all --message'
alias gcsm='git commit --signoff --message'
alias gcas='git commit --all --signoff'
alias gcasm='git commit --all --signoff --message'
alias gcb='git checkout -b'
alias gcf='git config --list'
function gccd() {
command git clone --recurse-submodules "$@"
[[ -d "$_" ]] && cd "$_" || cd "${${_:t}%.git}"
} }
compdef _git gccd=git-clone
alias gcl='git clone --recurse-submodules'
alias gclean='git clean --interactive -d'
alias gpristine='git reset --hard && git clean --force -dfx'
alias gcm='git checkout $(git_main_branch)'
alias gcd='git checkout $(git_develop_branch)'
alias gcmsg='git commit --message'
alias gco='git checkout'
alias gcor='git checkout --recurse-submodules'
alias gcount='git shortlog --summary --numbered'
alias gcp='git cherry-pick'
alias gcpa='git cherry-pick --abort'
alias gcpc='git cherry-pick --continue'
alias gcs='git commit --gpg-sign'
alias gcss='git commit --gpg-sign --signoff'
alias gcssm='git commit --gpg-sign --signoff --message'
alias gd='git diff'
alias gdca='git diff --cached'
alias gdcw='git diff --cached --word-diff'
alias gdct='git describe --tags $(git rev-list --tags --max-count=1)'
alias gds='git diff --staged'
alias gdt='git diff-tree --no-commit-id --name-only -r'
alias gdup='git diff @{upstream}'
alias gdw='git diff --word-diff'
function gdnolock() {
git diff "$@" ":(exclude)package-lock.json" ":(exclude)*.lock"
}
compdef _git gdnolock=git-diff
function gdv() { git diff -w "$@" | view - }
compdef _git gdv=git-diff
alias gf='git fetch'
# --jobs=<n> was added in git 2.8
is-at-least 2.8 "$git_version" \
&& alias gfa='git fetch --all --prune --jobs=10' \
|| alias gfa='git fetch --all --prune'
alias gfo='git fetch origin'
alias gfg='git ls-files | grep'
alias gg='git gui citool'
alias gga='git gui citool --amend'
function ggf() {
[[ "$#" != 1 ]] && local b="$(git_current_branch)"
git push --force origin "${b:=$1}"
}
compdef _git ggf=git-checkout
function ggfl() {
[[ "$#" != 1 ]] && local b="$(git_current_branch)"
git push --force-with-lease origin "${b:=$1}"
}
compdef _git ggfl=git-checkout
function ggl() {
if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
git pull origin "${*}"
else
[[ "$#" == 0 ]] && local b="$(git_current_branch)"
git pull origin "${b:=$1}"
fi
}
compdef _git ggl=git-checkout
function ggp() {
if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
git push origin "${*}"
else
[[ "$#" == 0 ]] && local b="$(git_current_branch)"
git push origin "${b:=$1}"
fi
}
compdef _git ggp=git-checkout
function ggpnp() {
if [[ "$#" == 0 ]]; then
ggl && ggp
else
ggl "${*}" && ggp "${*}"
fi
}
compdef _git ggpnp=git-checkout
function ggu() {
[[ "$#" != 1 ]] && local b="$(git_current_branch)"
git pull --rebase origin "${b:=$1}"
}
compdef _git ggu=git-checkout
alias ggpur='ggu'
alias ggpull='git pull origin "$(git_current_branch)"'
alias ggpush='git push origin "$(git_current_branch)"'
alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)'
alias gpsup='git push --set-upstream origin $(git_current_branch)'
is-at-least 2.30 "$git_version" \
&& alias gpsupf='git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes' \
|| alias gpsupf='git push --set-upstream origin $(git_current_branch) --force-with-lease'
alias ghh='git help'
alias gignore='git update-index --assume-unchanged'
alias gignored='git ls-files -v | grep "^[[:lower:]]"'
alias git-svn-dcommit-push='git svn dcommit && git push github $(git_main_branch):svntrunk'
alias gk='\gitk --all --branches &!'
alias gke='\gitk --all $(git log --walk-reflogs --pretty=%h) &!'
alias gl='git pull'
alias glg='git log --stat'
alias glgp='git log --stat --patch'
alias glgg='git log --graph'
alias glgga='git log --graph --decorate --all'
alias glgm='git log --graph --max-count=10'
alias glo='git log --oneline --decorate'
alias glol="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset'"
alias glols="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat"
alias glod="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset'"
alias glods="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short"
alias glola="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all"
alias glog='git log --oneline --decorate --graph'
alias gloga='git log --oneline --decorate --graph --all'
alias glp="_git_log_prettily"
alias gm='git merge'
alias gmom='git merge origin/$(git_main_branch)'
alias gmtl='git mergetool --no-prompt'
alias gmtlvim='git mergetool --no-prompt --tool=vimdiff'
alias gmum='git merge upstream/$(git_main_branch)'
alias gma='git merge --abort'
alias gms="git merge --squash"
alias gp='git push'
alias gpd='git push --dry-run'
is-at-least 2.30 "$git_version" \
&& alias gpf='git push --force-with-lease --force-if-includes' \
|| alias gpf='git push --force-with-lease'
alias gpf!='git push --force'
alias gpoat='git push origin --all && git push origin --tags'
alias gpod='git push origin --delete'
alias gpr='git pull --rebase'
alias gpu='git push upstream'
alias gpv='git push --verbose'
alias gr='git remote'
alias gra='git remote add'
alias grb='git rebase'
alias grba='git rebase --abort'
alias grbc='git rebase --continue'
alias grbd='git rebase $(git_develop_branch)'
alias grbi='git rebase --interactive'
alias grbm='git rebase $(git_main_branch)'
alias grbom='git rebase origin/$(git_main_branch)'
alias grbo='git rebase --onto'
alias grbs='git rebase --skip'
alias grev='git revert'
alias grh='git reset'
alias grhh='git reset --hard'
alias groh='git reset origin/$(git_current_branch) --hard'
alias grm='git rm'
alias grmc='git rm --cached'
alias grmv='git remote rename'
alias grrm='git remote remove'
alias grs='git restore'
alias grset='git remote set-url'
alias grss='git restore --source'
alias grst='git restore --staged'
alias grt='cd "$(git rev-parse --show-toplevel || echo .)"'
alias gru='git reset --'
alias grup='git remote update'
alias grv='git remote --verbose'
alias gsb='git status --short --branch'
alias gsd='git svn dcommit'
alias gsh='git show'
alias gsi='git submodule init'
alias gsps='git show --pretty=short --show-signature'
alias gsr='git svn rebase'
alias gss='git status --short'
alias gst='git status'
# use the default stash push on git 2.13 and newer
is-at-least 2.13 "$git_version" \
&& alias gsta='git stash push' \
|| alias gsta='git stash save'
alias gstaa='git stash apply'
alias gstc='git stash clear'
alias gstd='git stash drop'
alias gstl='git stash list'
alias gstp='git stash pop'
alias gsts='git stash show --text'
alias gstu='gsta --include-untracked'
alias gstall='git stash --all'
alias gsu='git submodule update'
alias gsw='git switch'
alias gswc='git switch --create'
alias gswm='git switch $(git_main_branch)'
alias gswd='git switch $(git_develop_branch)'
alias gts='git tag --sign'
alias gtv='git tag | sort -V'
alias gtl='gtl(){ git tag --sort=-v:refname -n --list "${1}*" }; noglob gtl'
alias gunignore='git update-index --no-assume-unchanged'
alias gunwip='git rev-list --max-count=1 --format="%s" HEAD | grep -q "\--wip--" && git reset HEAD~1'
alias gup='git pull --rebase'
alias gupv='git pull --rebase --verbose'
alias gupa='git pull --rebase --autostash'
alias gupav='git pull --rebase --autostash --verbose'
alias gupom='git pull --rebase origin $(git_main_branch)'
alias gupomi='git pull --rebase=interactive origin $(git_main_branch)'
alias glum='git pull upstream $(git_main_branch)'
alias gluc='git pull upstream $(git_current_branch)'
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 --message "--wip-- [skip ci]"'
alias gwt='git worktree'
alias gwta='git worktree add'
alias gwtls='git worktree list'
alias gwtmv='git worktree move'
alias gwtrm='git worktree remove'
alias gam='git am'
alias gamc='git am --continue'
alias gams='git am --skip'
alias gama='git am --abort'
alias gamscp='git am --show-current-patch'
function grename() { function grename() {
if [[ -z "$1" || -z "$2" ]]; then if [[ -z "$1" || -z "$2" ]]; then
@ -361,4 +56,307 @@ function grename() {
fi fi
} }
#
# Functions Work in Progress (WIP)
# (sorted alphabetically by function name)
# (order should follow README)
#
# Similar to `gunwip` but recursive "Unwips" all recent `--wip--` commits not just the last one
function gunwipall() {
local _commit=$(git log --grep='--wip--' --invert-grep --max-count=1 --format=format:%H)
# Check if a commit without "--wip--" was found and it's not the same as HEAD
if [[ "$_commit" != "$(git rev-parse HEAD)" ]]; then
git reset $_commit || return 1
fi
}
# Warn if the current branch is a WIP
function work_in_progress() {
command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!"
}
#
# Aliases
# (sorted alphabetically by command)
# (order should follow README)
# (in some cases force the alisas order to match README, like for example gke and gk)
#
alias grt='cd "$(git rev-parse --show-toplevel || echo .)"'
function ggpnp() {
if [[ "$#" == 0 ]]; then
ggl && ggp
else
ggl "${*}" && ggp "${*}"
fi
}
compdef _git ggpnp=git-checkout
alias ggpur='ggu'
alias g='git'
alias ga='git add'
alias gaa='git add --all'
alias gapa='git add --patch'
alias gau='git add --update'
alias gav='git add --verbose'
alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign --message "--wip-- [skip ci]"'
alias gam='git am'
alias gama='git am --abort'
alias gamc='git am --continue'
alias gamscp='git am --show-current-patch'
alias gams='git am --skip'
alias gap='git apply'
alias gapt='git apply --3way'
alias gbs='git bisect'
alias gbsb='git bisect bad'
alias gbsg='git bisect good'
alias gbsn='git bisect new'
alias gbso='git bisect old'
alias gbsr='git bisect reset'
alias gbss='git bisect start'
alias gbl='git blame -w'
alias gb='git branch'
alias gba='git branch --all'
alias gbd='git branch --delete'
alias gbD='git branch --delete --force'
alias gbda='git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null'
alias gbgd='LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d'
alias gbgD='LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D'
alias gbnm='git branch --no-merged'
alias gbr='git branch --remote'
alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)'
alias gbg='LANG=C git branch -vv | grep ": gone\]"'
alias gco='git checkout'
alias gcor='git checkout --recurse-submodules'
alias gcb='git checkout -b'
alias gcd='git checkout $(git_develop_branch)'
alias gcm='git checkout $(git_main_branch)'
alias gcp='git cherry-pick'
alias gcpa='git cherry-pick --abort'
alias gcpc='git cherry-pick --continue'
alias gclean='git clean --interactive -d'
alias gcl='git clone --recurse-submodules'
function gccd() {
command git clone --recurse-submodules "$@"
[[ -d "$_" ]] && cd "$_" || cd "${${_:t}%.git}"
}
compdef _git gccd=git-clone
alias gcam='git commit --all --message'
alias gcas='git commit --all --signoff'
alias gcasm='git commit --all --signoff --message'
alias gcs='git commit --gpg-sign'
alias gcss='git commit --gpg-sign --signoff'
alias gcssm='git commit --gpg-sign --signoff --message'
alias gcmsg='git commit --message'
alias gcsm='git commit --signoff --message'
alias gc='git commit --verbose'
alias gca='git commit --verbose --all'
alias gca!='git commit --verbose --all --amend'
alias gcan!='git commit --verbose --all --no-edit --amend'
alias gcans!='git commit --verbose --all --signoff --no-edit --amend'
alias gc!='git commit --verbose --amend'
alias gcn!='git commit --verbose --no-edit --amend'
alias gcf='git config --list'
alias gdct='git describe --tags $(git rev-list --tags --max-count=1)'
alias gd='git diff'
alias gdca='git diff --cached'
alias gdcw='git diff --cached --word-diff'
alias gds='git diff --staged'
alias gdw='git diff --word-diff'
function gdv() { git diff -w "$@" | view - }
compdef _git gdv=git-diff
alias gdup='git diff @{upstream}'
function gdnolock() {
git diff "$@" ":(exclude)package-lock.json" ":(exclude)*.lock"
}
compdef _git gdnolock=git-diff
alias gdt='git diff-tree --no-commit-id --name-only -r'
alias gf='git fetch'
# --jobs=<n> was added in git 2.8
is-at-least 2.8 "$git_version" \
&& alias gfa='git fetch --all --prune --jobs=10' \
|| alias gfa='git fetch --all --prune'
alias gfo='git fetch origin'
alias gg='git gui citool'
alias gga='git gui citool --amend'
alias ghh='git help'
alias glgg='git log --graph'
alias glgga='git log --graph --decorate --all'
alias glgm='git log --graph --max-count=10'
alias glods='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset" --date=short'
alias glod='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset"'
alias glola='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --all'
alias glols='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --stat'
alias glol='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset"'
alias glo='git log --oneline --decorate'
alias glog='git log --oneline --decorate --graph'
alias gloga='git log --oneline --decorate --graph --all'
# Pretty log messages
function _git_log_prettily(){
if ! [ -z $1 ]; then
git log --pretty=$1
fi
}
compdef _git _git_log_prettily=git-log
alias glp='_git_log_prettily'
alias glg='git log --stat'
alias glgp='git log --stat --patch'
alias gignored='git ls-files -v | grep "^[[:lower:]]"'
alias gfg='git ls-files | grep'
alias gm='git merge'
alias gma='git merge --abort'
alias gms="git merge --squash"
alias gmom='git merge origin/$(git_main_branch)'
alias gmum='git merge upstream/$(git_main_branch)'
alias gmtl='git mergetool --no-prompt'
alias gmtlvim='git mergetool --no-prompt --tool=vimdiff'
alias gl='git pull'
alias gpr='git pull --rebase'
alias gup='git pull --rebase'
alias gupa='git pull --rebase --autostash'
alias gupav='git pull --rebase --autostash --verbose'
alias gupv='git pull --rebase --verbose'
function ggu() {
[[ "$#" != 1 ]] && local b="$(git_current_branch)"
git pull --rebase origin "${b:=$1}"
}
compdef _git ggu=git-checkout
alias gupom='git pull --rebase origin $(git_main_branch)'
alias gupomi='git pull --rebase=interactive origin $(git_main_branch)'
alias ggpull='git pull origin "$(git_current_branch)"'
function ggl() {
if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
git pull origin "${*}"
else
[[ "$#" == 0 ]] && local b="$(git_current_branch)"
git pull origin "${b:=$1}"
fi
}
compdef _git ggl=git-checkout
alias gluc='git pull upstream $(git_current_branch)'
alias glum='git pull upstream $(git_main_branch)'
alias gp='git push'
alias gpd='git push --dry-run'
function ggf() {
[[ "$#" != 1 ]] && local b="$(git_current_branch)"
git push --force origin "${b:=$1}"
}
compdef _git ggf=git-checkout
alias gpf!='git push --force'
is-at-least 2.30 "$git_version" \
&& alias gpf='git push --force-with-lease --force-if-includes' \
|| alias gpf='git push --force-with-lease'
function ggfl() {
[[ "$#" != 1 ]] && local b="$(git_current_branch)"
git push --force-with-lease origin "${b:=$1}"
}
compdef _git ggfl=git-checkout
alias gpsup='git push --set-upstream origin $(git_current_branch)'
is-at-least 2.30 "$git_version" \
&& alias gpsupf='git push --set-upstream origin $(git_current_branch) --force-with-lease --force-if-includes' \
|| alias gpsupf='git push --set-upstream origin $(git_current_branch) --force-with-lease'
alias gpv='git push --verbose'
alias gpoat='git push origin --all && git push origin --tags'
alias gpod='git push origin --delete'
alias ggpush='git push origin "$(git_current_branch)"'
function ggp() {
if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
git push origin "${*}"
else
[[ "$#" == 0 ]] && local b="$(git_current_branch)"
git push origin "${b:=$1}"
fi
}
compdef _git ggp=git-checkout
alias gpu='git push upstream'
alias grb='git rebase'
alias grba='git rebase --abort'
alias grbc='git rebase --continue'
alias grbi='git rebase --interactive'
alias grbo='git rebase --onto'
alias grbs='git rebase --skip'
alias grbd='git rebase $(git_develop_branch)'
alias grbm='git rebase $(git_main_branch)'
alias grbom='git rebase origin/$(git_main_branch)'
alias gr='git remote'
alias grv='git remote --verbose'
alias gra='git remote add'
alias grrm='git remote remove'
alias grmv='git remote rename'
alias grset='git remote set-url'
alias grup='git remote update'
alias grh='git reset'
alias gru='git reset --'
alias grhh='git reset --hard'
alias gpristine='git reset --hard && git clean --force -dfx'
alias groh='git reset origin/$(git_current_branch) --hard'
alias grs='git restore'
alias grss='git restore --source'
alias grst='git restore --staged'
alias gunwip='git rev-list --max-count=1 --format="%s" HEAD | grep -q "\--wip--" && git reset HEAD~1'
alias grev='git revert'
alias grm='git rm'
alias grmc='git rm --cached'
alias gcount='git shortlog --summary --numbered'
alias gsh='git show'
alias gsps='git show --pretty=short --show-signature'
alias gstall='git stash --all'
alias gstaa='git stash apply'
alias gstc='git stash clear'
alias gstd='git stash drop'
alias gstl='git stash list'
alias gstp='git stash pop'
# use the default stash push on git 2.13 and newer
is-at-least 2.13 "$git_version" \
&& alias gsta='git stash push' \
|| alias gsta='git stash save'
alias gsts='git stash show --text'
alias gst='git status'
alias gss='git status --short'
alias gsb='git status --short --branch'
alias gsi='git submodule init'
alias gsu='git submodule update'
alias gsd='git svn dcommit'
alias git-svn-dcommit-push='git svn dcommit && git push github $(git_main_branch):svntrunk'
alias gsr='git svn rebase'
alias gsw='git switch'
alias gswc='git switch --create'
alias gswd='git switch $(git_develop_branch)'
alias gswm='git switch $(git_main_branch)'
alias gts='git tag --sign'
alias gtv='git tag | sort -V'
alias gignore='git update-index --assume-unchanged'
alias gunignore='git update-index --no-assume-unchanged'
alias gwch='git whatchanged -p --abbrev-commit --pretty=medium'
alias gwt='git worktree'
alias gwta='git worktree add'
alias gwtls='git worktree list'
alias gwtmv='git worktree move'
alias gwtrm='git worktree remove'
alias gstu='gsta --include-untracked'
alias gtl='gtl(){ git tag --sort=-v:refname -n --list "${1}*" }; noglob gtl'
alias gk='\gitk --all --branches &!'
alias gke='\gitk --all $(git log --walk-reflogs --pretty=%h) &!'
unset git_version unset git_version

View file

@ -1,6 +1,6 @@
# gitignore # gitignore
This plugin enables you the use of [gitignore.io](https://www.gitignore.io/) from the command line. You need an active internet connection. This plugin enables you the use of [gitignore.io](https://www.toptal.com/developers/gitignore) from the command line. You need an active internet connection.
To use it, add `gitignore` to the plugins array in your zshrc file: To use it, add `gitignore` to the plugins array in your zshrc file:

View file

@ -1,7 +1,7 @@
function gi() { curl -fLw '\n' https://www.gitignore.io/api/"${(j:,:)@}" } function gi() { curl -fLw '\n' https://www.toptal.com/developers/gitignore/api/"${(j:,:)@}" }
_gitignoreio_get_command_list() { _gitignoreio_get_command_list() {
curl -sfL https://www.gitignore.io/api/list | tr "," "\n" curl -sfL https://www.toptal.com/developers/gitignore/api/list | tr "," "\n"
} }
_gitignoreio () { _gitignoreio () {

View file

@ -2,8 +2,9 @@
# common grc.zsh paths # common grc.zsh paths
files=( files=(
/etc/grc.zsh # default /etc/grc.zsh # default
/usr/local/etc/grc.zsh # homebrew /usr/local/etc/grc.zsh # homebrew darwin-x64
/opt/homebrew/etc/grc.zsh # homebrew darwin-arm64
) )
# verify the file is readable and source it # verify the file is readable and source it

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
function spotify() { function spotify() {
# Copyright (c) 2012--2019 Harish Narayanan <mail@harishnarayanan.org> # Copyright (c) 2012--2023 Harish Narayanan <mail@harishnarayanan.org>
# #
# Contains numerous helpful contributions from Jorge Colindres, Thomas # Contains numerous helpful contributions from Jorge Colindres, Thomas
# Pritchard, iLan Epstein, Gabriele Bonetti, Sean Heller, Eric Martin # Pritchard, iLan Epstein, Gabriele Bonetti, Sean Heller, Eric Martin
@ -35,6 +35,9 @@ if ! [[ -f "${USER_CONFIG_FILE}" ]]; then
fi fi
source "${USER_CONFIG_FILE}"; source "${USER_CONFIG_FILE}";
# Set the percent change in volume for vol up and vol down
VOL_INCREMENT=10
showAPIHelp() { showAPIHelp() {
echo; echo;
echo "Connecting to Spotify's API:"; echo "Connecting to Spotify's API:";
@ -170,12 +173,12 @@ while [ $# -gt 0 ]; do
if [ -z "${CLIENT_ID}" ]; then if [ -z "${CLIENT_ID}" ]; then
cecho "Invalid Client ID, please update ${USER_CONFIG_FILE}"; cecho "Invalid Client ID, please update ${USER_CONFIG_FILE}";
showAPIHelp; showAPIHelp;
return 1 return 1;
fi fi
if [ -z "${CLIENT_SECRET}" ]; then if [ -z "${CLIENT_SECRET}" ]; then
cecho "Invalid Client Secret, please update ${USER_CONFIG_FILE}"; cecho "Invalid Client Secret, please update ${USER_CONFIG_FILE}";
showAPIHelp; showAPIHelp;
return 1 return 1;
fi fi
SHPOTIFY_CREDENTIALS=$(printf "${CLIENT_ID}:${CLIENT_SECRET}" | base64 | tr -d "\n"|tr -d '\r'); SHPOTIFY_CREDENTIALS=$(printf "${CLIENT_ID}:${CLIENT_SECRET}" | base64 | tr -d "\n"|tr -d '\r');
SPOTIFY_PLAY_URI=""; SPOTIFY_PLAY_URI="";
@ -198,7 +201,7 @@ while [ $# -gt 0 ]; do
fi fi
SPOTIFY_ACCESS_TOKEN=$( \ SPOTIFY_ACCESS_TOKEN=$( \
printf "${SPOTIFY_TOKEN_RESPONSE_DATA}" \ printf "${SPOTIFY_TOKEN_RESPONSE_DATA}" \
| grep -E -o '"access_token":".*",' \ | command grep -E -o '"access_token":".*",' \
| sed 's/"access_token"://g' \ | sed 's/"access_token"://g' \
| sed 's/"//g' \ | sed 's/"//g' \
| sed 's/,.*//g' \ | sed 's/,.*//g' \
@ -219,9 +222,8 @@ while [ $# -gt 0 ]; do
-H "Accept: application/json" \ -H "Accept: application/json" \
--data-urlencode "q=$Q" \ --data-urlencode "q=$Q" \
-d "type=$type&limit=1&offset=0" \ -d "type=$type&limit=1&offset=0" \
| grep -E -o "spotify:$type:[a-zA-Z0-9]+" -m 1 | command grep -E -o "spotify:$type:[a-zA-Z0-9]+" -m 1
) )
echo "play uri: ${SPOTIFY_PLAY_URI}"
} }
case $2 in case $2 in
@ -235,11 +237,11 @@ while [ $# -gt 0 ]; do
results=$( \ results=$( \
curl -s -G $SPOTIFY_SEARCH_API --data-urlencode "q=$Q" -d "type=playlist&limit=10&offset=0" -H "Accept: application/json" -H "Authorization: Bearer ${SPOTIFY_ACCESS_TOKEN}" \ curl -s -G $SPOTIFY_SEARCH_API --data-urlencode "q=$Q" -d "type=playlist&limit=10&offset=0" -H "Accept: application/json" -H "Authorization: Bearer ${SPOTIFY_ACCESS_TOKEN}" \
| grep -E -o "spotify:playlist:[a-zA-Z0-9]+" -m 10 \ | command grep -E -o "spotify:playlist:[a-zA-Z0-9]+" -m 10 \
) )
count=$( \ count=$( \
echo "$results" | grep -c "spotify:playlist" \ echo "$results" | command grep -c "spotify:playlist" \
) )
if [ "$count" -gt 0 ]; then if [ "$count" -gt 0 ]; then
@ -333,16 +335,16 @@ while [ $# -gt 0 ]; do
cecho "Current Spotify volume level is $vol."; cecho "Current Spotify volume level is $vol.";
break ; break ;
elif [ "$2" = "up" ]; then elif [ "$2" = "up" ]; then
if [ $vol -le 90 ]; then if [ $vol -le $(( 100-$VOL_INCREMENT )) ]; then
newvol=$(( vol+10 )); newvol=$(( vol+$VOL_INCREMENT ));
cecho "Increasing Spotify volume to $newvol."; cecho "Increasing Spotify volume to $newvol.";
else else
newvol=100; newvol=100;
cecho "Spotify volume level is at max."; cecho "Spotify volume level is at max.";
fi fi
elif [ "$2" = "down" ]; then elif [ "$2" = "down" ]; then
if [ $vol -ge 10 ]; then if [ $vol -ge $(( $VOL_INCREMENT )) ]; then
newvol=$(( vol-10 )); newvol=$(( vol-$VOL_INCREMENT ));
cecho "Reducing Spotify volume to $newvol."; cecho "Reducing Spotify volume to $newvol.";
else else
newvol=0; newvol=0;
@ -354,11 +356,11 @@ while [ $# -gt 0 ]; do
else else
echo "Improper use of 'vol' command" echo "Improper use of 'vol' command"
echo "The 'vol' command should be used as follows:" echo "The 'vol' command should be used as follows:"
echo " vol up # Increases the volume by 10%."; echo " vol up # Increases the volume by $VOL_INCREMENT%.";
echo " vol down # Decreases the volume by 10%."; echo " vol down # Decreases the volume by $VOL_INCREMENT%.";
echo " vol [amount] # Sets the volume to an amount between 0 and 100."; echo " vol [amount] # Sets the volume to an amount between 0 and 100.";
echo " vol # Shows the current Spotify volume."; echo " vol # Shows the current Spotify volume.";
return 1 return 1;
fi fi
osascript -e "tell application \"Spotify\" to set sound volume to $newvol"; osascript -e "tell application \"Spotify\" to set sound volume to $newvol";
@ -468,10 +470,9 @@ while [ $# -gt 0 ]; do
"help" ) "help" )
showHelp; showHelp;
break ;; break ;;
* ) * )
showHelp; showHelp;
return 1 ;; return 1;
esac esac
done done

View file

@ -1,6 +1,7 @@
# Pipenv # Pipenv
## Installation ## Installation
In your `.zshrc` file, add `pipenv` to the plugins section In your `.zshrc` file, add `pipenv` to the plugins section
``` ```
@ -8,7 +9,9 @@ plugins=(... pipenv ...)
``` ```
## Features ## Features
This plugin provides some features to simplify the use of Pipenv while working on ZSH. This plugin provides some features to simplify the use of Pipenv while working on ZSH.
- Adds completion for pipenv - Adds completion for pipenv
- Auto activates and deactivates pipenv shell - Auto activates and deactivates pipenv shell
- Adds short aliases for common pipenv commands - Adds short aliases for common pipenv commands
@ -27,3 +30,13 @@ This plugin provides some features to simplify the use of Pipenv while working o
- `pwh` is aliased to `pipenv --where` - `pwh` is aliased to `pipenv --where`
- `pvenv` is aliased to `pipenv --venv` - `pvenv` is aliased to `pipenv --venv`
- `ppy` is aliased to `pipenv --py` - `ppy` is aliased to `pipenv --py`
## Configuration
### Shell activation
If you want to disable the shell activation and deactivation feature, add the following style to your `.zshrc` before sourcing `oh-my-zsh.sh`:
```zsh
zstyle ':omz:plugins:pipenv' auto-shell no
```

View file

@ -12,28 +12,30 @@ fi
_PIPENV_COMPLETE=zsh_source pipenv >| "$ZSH_CACHE_DIR/completions/_pipenv" &| _PIPENV_COMPLETE=zsh_source pipenv >| "$ZSH_CACHE_DIR/completions/_pipenv" &|
# Automatic pipenv shell activation/deactivation if zstyle -T ':omz:plugins:pipenv' auto-shell; then
_togglePipenvShell() { # Automatic pipenv shell activation/deactivation
# deactivate shell if Pipfile doesn't exist and not in a subdir _togglePipenvShell() {
if [[ ! -f "$PWD/Pipfile" ]]; then # deactivate shell if Pipfile doesn't exist and not in a subdir
if [[ "$PIPENV_ACTIVE" == 1 ]]; then if [[ ! -f "$PWD/Pipfile" ]]; then
if [[ "$PWD" != "$pipfile_dir"* ]]; then if [[ "$PIPENV_ACTIVE" == 1 ]]; then
exit if [[ "$PWD" != "$pipfile_dir"* ]]; then
exit
fi
fi fi
fi fi
fi
# activate the shell if Pipfile exists # activate the shell if Pipfile exists
if [[ "$PIPENV_ACTIVE" != 1 ]]; then if [[ "$PIPENV_ACTIVE" != 1 ]]; then
if [[ -f "$PWD/Pipfile" ]]; then if [[ -f "$PWD/Pipfile" ]]; then
export pipfile_dir="$PWD" export pipfile_dir="$PWD"
pipenv shell pipenv shell
fi
fi fi
fi }
} autoload -U add-zsh-hook
autoload -U add-zsh-hook add-zsh-hook chpwd _togglePipenvShell
add-zsh-hook chpwd _togglePipenvShell _togglePipenvShell
_togglePipenvShell fi
# Aliases # Aliases
alias pch="pipenv check" alias pch="pipenv check"

47
plugins/podman/README.md Normal file
View file

@ -0,0 +1,47 @@
# Podman plugin
This plugin adds auto-completion and aliases for [podman](https://podman.io/).
To use it add `podman` to the plugins array in your zshrc file.
```zsh
plugins=(... podman)
```
## Aliases
| Alias | Command | Description |
| :------ | :-------------------------------------------- | :--------------------------------------------------------------------------------------- |
| pbl | `podman build` | Build an image from a Dockerfile |
| pcin | `podman container inspect` | Display detailed information on one or more containers |
| pcls | `podman container ls` | List all the running podman containers |
| pclsa | `podman container ls --all` | List all running and stopped containers |
| pib | `podman image build` | Build an image from a Dockerfile (same as podman build) |
| pii | `podman image inspect` | Display detailed information on one or more images |
| pils | `podman image ls` | List podman images |
| pipu | `podman image push` | Push an image or repository to a remote registry |
| pirm | `podman image rm` | Remove one or more images |
| pit | `podman image tag` | Add a name and tag to a particular image |
| plo | `podman container logs` | Fetch the logs of a podman container |
| pnc | `podman network create` | Create a new network |
| pncn | `podman network connect` | Connect a container to a network |
| pndcn | `podman network disconnect` | Disconnect a container from a network |
| pni | `podman network inspect` | Return information about one or more networks |
| pnls | `podman network ls` | List all networks the engine daemon knows about, including those spanning multiple hosts |
| pnrm | `podman network rm` | Remove one or more networks |
| ppo | `podman container port` | List port mappings or a specific mapping for the container |
| ppu | `podman pull` | Pull an image or a repository from a registry |
| pr | `podman container run` | Create a new container and start it using the specified command |
| prit | `podman container run --interactive --tty` | Create a new container and start it in an interactive shell |
| prm | `podman container rm` | Remove the specified container(s) |
| prm! | `podman container rm --force` | Force the removal of a running container (uses SIGKILL) |
| pst | `podman container start` | Start one or more stopped containers |
| prs | `podman container restart` | Restart one or more containers |
| psta | `podman stop $(podman ps -q)` | Stop all running containers |
| pstp | `podman container stop` | Stop one or more running containers |
| ptop | `podman top` | Display the running processes of a container |
| pvi | `podman volume inspect` | Display detailed information about one or more volumes |
| pvls | `podman volume ls` | List all the volumes known to podman |
| pvprune | `podman volume prune` | Cleanup dangling volumes |
| pxc | `podman container exec` | Run a new command in a running container |
| pxcit | `podman container exec --interactive --tty` | Run a new command in a running container in an interactive shell |

View file

@ -0,0 +1,47 @@
if (( ! $+commands[podman] )); then
return
fi
# If the completion file doesn't exist yet, we need to autoload it and
# bind it to `podman`. Otherwise, compinit will have already done that.
if [[ ! -f "$ZSH_CACHE_DIR/completions/_podman" ]]; then
typeset -g -A _comps
autoload -Uz _podman
_comps[podman]=_podman
fi
podman completion zsh 2> /dev/null >| "$ZSH_CACHE_DIR/completions/_podman" &|
alias pbl='podman build'
alias pcin='podman container inspect'
alias pcls='podman container ls'
alias pclsa='podman container ls --all'
alias pib='podman image build'
alias pii='podman image inspect'
alias pils='podman image ls'
alias pipu='podman image push'
alias pirm='podman image rm'
alias pit='podman image tag'
alias plo='podman container logs'
alias pnc='podman network create'
alias pncn='podman network connect'
alias pndcn='podman network disconnect'
alias pni='podman network inspect'
alias pnls='podman network ls'
alias pnrm='podman network rm'
alias ppo='podman container port'
alias ppu='podman pull'
alias pr='podman container run'
alias prit='podman container run --interactive --tty'
alias prm='podman container rm'
alias 'prm!'='podman container rm --force'
alias pst='podman container start'
alias prs='podman container restart'
alias psta='podman stop $(podman ps --quiet)'
alias pstp='podman container stop'
alias ptop='podman top'
alias pvi='podman volume inspect'
alias pvls='podman volume ls'
alias pvprune='podman volume prune'
alias pxc='podman container exec'
alias pxcit='podman container exec --interactive --tty'

20
plugins/qodana/README.md Normal file
View file

@ -0,0 +1,20 @@
# JetBrains Qodana CLI plugin
This plugin adds completion for the [JetBrains Qodana CLI](https://github.com/JetBrains/qodana-cli).
To use it, add `qodana` to the plugins array in your zshrc file:
```zsh
plugins=(... qodana)
```
This plugin does not add any aliases.
## Cache
This plugin caches the completion script and is automatically updated when the
plugin is loaded, which is usually when you start up a new terminal emulator.
The cache is stored at:
- `$ZSH_CACHE_DIR/completions/_qodana` completions script

View file

@ -0,0 +1,14 @@
# Autocompletion for the JetBrains Qodana CLI (qodana).
if (( ! $+commands[qodana] )); then
return
fi
# If the completion file doesn't exist yet, we need to autoload it and
# bind it to `qodana`. Otherwise, compinit will have already done that.
if [[ ! -f "$ZSH_CACHE_DIR/completions/_qodana" ]]; then
typeset -g -A _comps
autoload -Uz _qodana
_comps[qodana]=_qodana
fi
qodana completion zsh >| "$ZSH_CACHE_DIR/completions/_qodana" &|

View file

@ -12,6 +12,7 @@ plugins=(... systemd)
| Alias | Command | Description | | Alias | Command | Description |
|:-----------------------|:-----------------------------------|:-----------------------------------------------------------------| |:-----------------------|:-----------------------------------|:-----------------------------------------------------------------|
| `sc-failed` | `systemctl --failed` | List failed systemd units |
| `sc-list-units` | `systemctl list-units` | List all units systemd has in memory | | `sc-list-units` | `systemctl list-units` | List all units systemd has in memory |
| `sc-is-active` | `systemctl is-active` | Show whether a unit is active | | `sc-is-active` | `systemctl is-active` | Show whether a unit is active |
| `sc-status` | `systemctl status` | Show terse runtime status information about one or more units | | `sc-status` | `systemctl status` | Show terse runtime status information about one or more units |

View file

@ -93,6 +93,9 @@ alias scu-enable-now="scu-enable --now"
alias scu-disable-now="scu-disable --now" alias scu-disable-now="scu-disable --now"
alias scu-mask-now="scu-mask --now" alias scu-mask-now="scu-mask --now"
# --failed commands
alias scu-failed='systemctl --user --failed'
alias sc-failed='systemctl --failed'
function systemd_prompt_info { function systemd_prompt_info {
local unit local unit

View file

@ -1,7 +1,7 @@
# Terraform plugin # Terraform plugin
Plugin for Terraform, a tool from Hashicorp for managing infrastructure safely and efficiently. Plugin for Terraform, a tool from Hashicorp for managing infrastructure safely and efficiently. It adds
It adds completion for `terraform`, as well as aliases and a prompt function. completion for `terraform`, as well as aliases and a prompt function.
To use it, add `terraform` to the plugins array of your `~/.zshrc` file: To use it, add `terraform` to the plugins array of your `~/.zshrc` file:
@ -11,7 +11,7 @@ plugins=(... terraform)
## Requirements ## Requirements
* [Terraform](https://terraform.io/) - [Terraform](https://terraform.io/)
## Aliases ## Aliases
@ -29,11 +29,12 @@ plugins=(... terraform)
## Prompt function ## Prompt function
You can add the current Terraform workspace in your prompt by adding `$(tf_prompt_info)` You can add the current Terraform workspace in your prompt by adding `$(tf_prompt_info)`,
to your `PROMPT` or `RPROMPT` variable. `$(tf_version_prompt_info)` to your `PROMPT` or `RPROMPT` variable.
```sh ```sh
RPROMPT='$(tf_prompt_info)' RPROMPT='$(tf_prompt_info)'
RPROMPT='$(tf_version_prompt_info)'
``` ```
You can also specify the PREFIX and SUFFIX for the workspace with the following variables: You can also specify the PREFIX and SUFFIX for the workspace with the following variables:
@ -41,4 +42,6 @@ You can also specify the PREFIX and SUFFIX for the workspace with the following
```sh ```sh
ZSH_THEME_TF_PROMPT_PREFIX="%{$fg[white]%}" ZSH_THEME_TF_PROMPT_PREFIX="%{$fg[white]%}"
ZSH_THEME_TF_PROMPT_SUFFIX="%{$reset_color%}" ZSH_THEME_TF_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_TF_VERSION_PROMPT_PREFIX="%{$fg[white]%}"
ZSH_THEME_TF_VERSION_PROMPT_SUFFIX="%{$reset_color%}"
``` ```

View file

@ -8,6 +8,13 @@ function tf_prompt_info() {
echo "${ZSH_THEME_TF_PROMPT_PREFIX-[}${workspace:gs/%/%%}${ZSH_THEME_TF_PROMPT_SUFFIX-]}" echo "${ZSH_THEME_TF_PROMPT_PREFIX-[}${workspace:gs/%/%%}${ZSH_THEME_TF_PROMPT_SUFFIX-]}"
} }
function tf_version_prompt_info() {
local terraform_version
terraform_version=$(terraform --version | head -n 1 | cut -d ' ' -f 2)
echo "${ZSH_THEME_TF_VERSION_PROMPT_PREFIX-[}${terraform_version:gs/%/%%}${ZSH_THEME_TF_VERSION_PROMPT_SUFFIX-]}"
}
alias tf='terraform' alias tf='terraform'
alias tfa='terraform apply' alias tfa='terraform apply'
alias tfc='terraform console' alias tfc='terraform console'

View file

@ -28,16 +28,16 @@ The plugin also supports the following:
## Configuration Variables ## Configuration Variables
| Variable | Description | | Variable | Description |
| ----------------------------------- | ----------------------------------------------------------------------------- | | ----------------------------------- | ------------------------------------------------------------------------------------------- |
| `ZSH_TMUX_AUTOSTART` | Automatically starts tmux (default: `false`) | | `ZSH_TMUX_AUTOSTART` | Automatically starts tmux (default: `false`) |
| `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) | | `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) |
| `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) | | `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) |
| `ZSH_TMUX_AUTOQUIT` | Automatically closes terminal once tmux exits (default: `ZSH_TMUX_AUTOSTART`) | | `ZSH_TMUX_AUTOQUIT` | Automatically closes terminal once tmux exits (default: `ZSH_TMUX_AUTOSTART`) |
| `ZSH_TMUX_FIXTERM` | Sets `$TERM` to 256-color term or not based on current terminal support | | `ZSH_TMUX_FIXTERM` | Sets `$TERM` to 256-color term or not based on current terminal support |
| `ZSH_TMUX_ITERM2` | Sets the `-CC` option for iTerm2 tmux integration (default: `false`) | | `ZSH_TMUX_ITERM2` | Sets the `-CC` option for iTerm2 tmux integration (default: `false`) |
| `ZSH_TMUX_FIXTERM_WITHOUT_256COLOR` | `$TERM` to use for non 256-color terminals (default: `screen`) | | `ZSH_TMUX_FIXTERM_WITHOUT_256COLOR` | `$TERM` to use for non 256-color terminals (default: `screen`) |
| `ZSH_TMUX_FIXTERM_WITH_256COLOR` | `$TERM` to use for 256-color terminals (default: `screen-256color` | | `ZSH_TMUX_FIXTERM_WITH_256COLOR` | `$TERM` to use for 256-color terminals (default: `screen-256color` |
| `ZSH_TMUX_CONFIG` | Set the configuration path (default: `$HOME/.tmux.conf`) | | `ZSH_TMUX_CONFIG` | Set the configuration path (default: `$HOME/.tmux.conf`, `$XDG_CONFIG_HOME/tmux/tmux.conf`) |
| `ZSH_TMUX_UNICODE` | Set `tmux -u` option to support unicode | | `ZSH_TMUX_UNICODE` | Set `tmux -u` option to support unicode |
| `ZSH_TMUX_DEFAULT_SESSION_NAME` | Set tmux default session name when autostart is enabled | | `ZSH_TMUX_DEFAULT_SESSION_NAME` | Set tmux default session name when autostart is enabled |

View file

@ -26,12 +26,17 @@ fi
# systems without the proper terminfo # systems without the proper terminfo
: ${ZSH_TMUX_FIXTERM_WITH_256COLOR:=screen-256color} : ${ZSH_TMUX_FIXTERM_WITH_256COLOR:=screen-256color}
# Set the configuration path # Set the configuration path
: ${ZSH_TMUX_CONFIG:=$HOME/.tmux.conf} if [[ -e $HOME/.tmux.conf ]]; then
: ${ZSH_TMUX_CONFIG:=$HOME/.tmux.conf}
elif [[ -e ${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf ]]; then
: ${ZSH_TMUX_CONFIG:=${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf}
else
: ${ZSH_TMUX_CONFIG:=$HOME/.tmux.conf}
fi
# Set -u option to support unicode # Set -u option to support unicode
: ${ZSH_TMUX_UNICODE:=false} : ${ZSH_TMUX_UNICODE:=false}
# ALIASES # ALIASES
alias ta='tmux attach -t' alias ta='tmux attach -t'
alias tad='tmux attach -d -t' alias tad='tmux attach -d -t'
alias ts='tmux new-session -s' alias ts='tmux new-session -s'

View file

@ -25,6 +25,7 @@ function web_search() {
archive "https://web.archive.org/web/*/" archive "https://web.archive.org/web/*/"
scholar "https://scholar.google.com/scholar?q=" scholar "https://scholar.google.com/scholar?q="
ask "https://www.ask.com/web?q=" ask "https://www.ask.com/web?q="
youtube "https://www.youtube.com/results?search_query="
) )
# check whether the search engine is supported # check whether the search engine is supported
@ -66,11 +67,12 @@ alias wolframalpha='web_search wolframalpha'
alias archive='web_search archive' alias archive='web_search archive'
alias scholar='web_search scholar' alias scholar='web_search scholar'
alias ask='web_search ask' alias ask='web_search ask'
alias youtube='web_search youtube'
#add your own !bang searches here #add your own !bang searches here
alias wiki='web_search duckduckgo \!w' alias wiki='web_search duckduckgo \!w'
alias news='web_search duckduckgo \!n' alias news='web_search duckduckgo \!n'
alias youtube='web_search duckduckgo \!yt' #alias youtube='web_search duckduckgo \!yt'
alias map='web_search duckduckgo \!m' alias map='web_search duckduckgo \!m'
alias image='web_search duckduckgo \!i' alias image='web_search duckduckgo \!i'
alias ducky='web_search duckduckgo \!' alias ducky='web_search duckduckgo \!'

View file

@ -1,24 +1,140 @@
# Depends on the git plugin for work_in_progress() # Depends on the git plugin for work_in_progress()
(( $+functions[work_in_progress] )) || work_in_progress() {} (( $+functions[work_in_progress] )) || work_in_progress() {}
ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}[" ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[cyan]%}[%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg[cyan]%}]"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}" ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_CLEAN="" ZSH_THEME_GIT_PROMPT_CLEAN=""
# Customized git status, oh-my-zsh currently does not allow render dirty status before branch # Customized git status, oh-my-zsh currently does not allow render dirty status before branch
git_custom_status() { git_custom_status() {
local branch=$(git_current_branch) local branch=$(git_current_branch)
[[ -n "$branch" ]] || return 0 [[ -n "$branch" ]] || return 0
echo "$(parse_git_dirty)\ print "%{${fg_bold[yellow]}%}$(work_in_progress)%{$reset_color%}\
%{${fg_bold[yellow]}%}$(work_in_progress)%{$reset_color%}\ ${ZSH_THEME_GIT_PROMPT_PREFIX}$(parse_git_dirty)${branch}\
${ZSH_THEME_GIT_PROMPT_PREFIX}${branch}${ZSH_THEME_GIT_PROMPT_SUFFIX}" ${ZSH_THEME_GIT_PROMPT_SUFFIX}"
}
autoload -U colors && colors
#export VCS_PROMPT=hg_prompt_info
export VCS_PROMPT=git_custom_status
base_prompt="%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b "
custom_prompt=""
last_run_time=""
last_vcs_info=""
function pipestatus_parse {
PIPESTATUS="$pipestatus"
ERROR=0
for i in "${(z)PIPESTATUS}"; do
if [[ "$i" -ne 0 ]]; then
ERROR=1
fi
done
if [[ "$ERROR" -ne 0 ]]; then
print "[%{$fg[red]%}$PIPESTATUS%{$fg[cyan]%}]"
fi
} }
# RVM component of prompt
ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg[red]%}["
ZSH_THEME_RUBY_PROMPT_SUFFIX="]%{$reset_color%}"
# Combine it all into a final right-side prompt # Combine it all into a final right-side prompt
RPS1="\$(git_custom_status)\$(ruby_prompt_info)${RPS1:+ $RPS1}"
PROMPT='%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b ' PROMPT='%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b '
function preexec() {
last_run_time=$(perl -MTime::HiRes=time -e 'printf "%.9f\n", time')
}
function duration() {
local duration
local now=$(perl -MTime::HiRes=time -e 'printf "%.9f\n", time')
local last=$1
local last_split=("${(@s/./)last}")
local now_split=("${(@s/./)now}")
local T=$((now_split[1] - last_split[1]))
local D=$((T/60/60/24))
local H=$((T/60/60%24))
local M=$((T/60%60))
local S=$((T%60))
local s=$(((now_split[2] - last_split[2]) / 1000000000.))
local m=$(((now_split[2] - last_split[2]) / 1000000.))
(( $D > 0 )) && duration+="${D}d"
(( $H > 0 )) && duration+="${H}h"
(( $M > 0 )) && duration+="${M}m"
if [[ $S -le 0 ]]; then
printf "%ims" "$m"
else
if ! [[ -z $duration ]] && printf "%s" "$duration"
local sec_milli=$((S + s))
printf "%.3fs" "$sec_milli"
fi
}
function precmd() {
RETVAL=$(pipestatus_parse)
local info=""
if [ ! -z "$last_run_time" ]; then
local elapsed=$(duration $last_run_time)
last_run_time=$(print $last_run_time | tr -d ".")
if [ $(( $(perl -MTime::HiRes=time -e 'printf "%.9f\n", time' | tr -d ".") - $last_run_time )) -gt $(( 120 * 1000 * 1000 * 1000 )) ]; then
local elapsed_color="%{$fg[magenta]%}"
elif [ $(( $(perl -MTime::HiRes=time -e 'printf "%.9f\n", time' | tr -d ".") - $last_run_time )) -gt $(( 60 * 1000 * 1000 * 1000 )) ]; then
local elapsed_color="%{$fg[red]%}"
elif [ $(( $(perl -MTime::HiRes=time -e 'printf "%.9f\n", time' | tr -d ".") - $last_run_time )) -gt $(( 10 * 1000 * 1000 * 1000 )) ]; then
local elapsed_color="%{$fg[yellow]%}"
else
local elapsed_color="%{$fg[green]%}"
fi
info=$(printf "%s%s%s%s%s" "%{$fg[cyan]%}[" "$elapsed_color" "$elapsed" "%{$fg[cyan]%}]" "$RETVAL")
unset last_run_time
fi
if [ -z "$info" -a ! -z "$last_vcs_info" ]; then
custom_prompt="$last_vcs_info$base_prompt"
return;
fi
if (( ${+VCS_PROMPT} )); then
last_vcs_info=$($VCS_PROMPT)
if [ ! -z "$last_vcs_info" ]; then
[ -z "$info" ] && info=$last_vcs_info || info="$info$last_vcs_info"
fi
fi
[ -z "$info" ] && custom_prompt="$base_prompt" || custom_prompt="$info$base_prompt"
}
function hg_prompt_info() {
unset output info parts branch_parts branch
local output=""
if ! output="$(hg status 2> /dev/null)"; then
return
fi
local info=$(hg log -l1 --template '{author}:{node|short}:{remotenames}:{phabdiff}')
local parts=(${(@s/:/)info})
local branch_parts=(${(@s,/,)parts[3]})
local branch=${branch_parts[-1]}
[ ! -z "${parts[3]}" ] && [[ "${parts[1]}" =~ "$USER@" ]] && branch=${parts[3]}
[ -z "${parts[3]}" ] && branch=${parts[2]}
if [[ ! -z "$output" ]]; then
local color="%{$fg[red]%}"
elif [[ "${branch}" == "master" || "${branch}" == "warm" ]]; then
local color="%{$fg[yellow]%}"
else
local color="%{$fg[green]%}"
fi
print "%{$fg[cyan]%}[${color}${branch}%{$fg[cyan]%}]"
}
setopt PROMPT_SUBST
PROMPT='$custom_prompt'

View file

@ -51,8 +51,14 @@ function ssh_connection() {
fi fi
} }
function _toolbox_prompt_info() {
if typeset -f toolbox_prompt_info > /dev/null; then
toolbox_prompt_info
fi
}
local ret_status="%(?:%{$fg_bold[green]%}:%{$fg_bold[red]%})%?%{$reset_color%}" local ret_status="%(?:%{$fg_bold[green]%}:%{$fg_bold[red]%})%?%{$reset_color%}"
PROMPT=$'\n$(ssh_connection)%{$fg_bold[green]%}%n@%m%{$reset_color%}$(my_git_prompt) : %~\n[${ret_status}] %# ' PROMPT=$'\n$(_toolbox_prompt_info)$(ssh_connection)%{$fg_bold[green]%}%n@%m%{$reset_color%}$(my_git_prompt) : %~\n[${ret_status}] %# '
ZSH_THEME_PROMPT_RETURNCODE_PREFIX="%{$fg_bold[red]%}" ZSH_THEME_PROMPT_RETURNCODE_PREFIX="%{$fg_bold[red]%}"
ZSH_THEME_GIT_PROMPT_PREFIX=" $fg[white] %{$fg_bold[yellow]%}" ZSH_THEME_GIT_PROMPT_PREFIX=" $fg[white] %{$fg_bold[yellow]%}"

View file

@ -0,0 +1,24 @@
# Depends on the git plugin for work_in_progress()
(( $+functions[work_in_progress] )) || work_in_progress() {}
ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}["
ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=""
# Customized git status, oh-my-zsh currently does not allow render dirty status before branch
git_custom_status() {
local branch=$(git_current_branch)
[[ -n "$branch" ]] || return 0
echo "$(parse_git_dirty)\
%{${fg_bold[yellow]}%}$(work_in_progress)%{$reset_color%}\
${ZSH_THEME_GIT_PROMPT_PREFIX}${branch}${ZSH_THEME_GIT_PROMPT_SUFFIX}"
}
# RVM component of prompt
ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg[red]%}["
ZSH_THEME_RUBY_PROMPT_SUFFIX="]%{$reset_color%}"
# Combine it all into a final right-side prompt
RPS1="\$(git_custom_status)\$(ruby_prompt_info)${RPS1:+ $RPS1}"
PROMPT='%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b '

View file

@ -366,7 +366,7 @@ function display-release {
# In text mode, highlight (#<issue>) and dim text between `backticks` # In text mode, highlight (#<issue>) and dim text between `backticks`
text) text)
if supports_hyperlinks; then if supports_hyperlinks; then
sed -E $'s|#([0-9]+)|\e]8;;https://github.com/ohmyzsh/ohmyzsh/issues/\\1\a\e[32m#\\1\e[0m\e]8;;\a|g' <<< "$subject" sed -E $'s|#([0-9]+)|\e]8;;https://github.com/ohmyzsh/ohmyzsh/issues/\\1\a\e[32m#\\1\e[0m\e]8;;\a|g;s|`([^`]+)`|`\e[2m\\1\e[0m`|g' <<< "$subject"
else else
sed -E $'s|#([0-9]+)|\e[32m#\\1\e[0m|g;s|`([^`]+)`|`\e[2m\\1\e[0m`|g' <<< "$subject" sed -E $'s|#([0-9]+)|\e[32m#\\1\e[0m|g;s|`([^`]+)`|`\e[2m\\1\e[0m`|g' <<< "$subject"
fi ;; fi ;;

View file

@ -1,4 +1,5 @@
#!/usr/bin/env zsh #!/usr/bin/env zsh
set +u # disable nounset
local ret=0 # exit code local ret=0 # exit code