Merge branch 'ohmyzsh:master' into master

This commit is contained in:
Vigneshwar Ravichandar 2021-11-13 19:50:36 +05:30 committed by GitHub
commit 1d11c6eef6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
78 changed files with 1459 additions and 876 deletions

View file

@ -202,7 +202,7 @@ type(scope)!: subject
feat(archlinux): add support for aura AUR helper (#9467)
```
- Formatted inline code by using backticks: the text inbetween backticks will also be highlighted by
- Formatted inline code by using backticks: the text between backticks will also be highlighted by
the changelog tool:
```
feat(shell-proxy): enable unexported `DEFAULT_PROXY` setting (#9774)

View file

@ -42,7 +42,7 @@ It's a good idea to inspect the install script from projects you don't yet know.
that by downloading the install script first, looking through it so everything looks normal,
then running it:
```shell
```sh
wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
sh install.sh
```
@ -57,18 +57,18 @@ Oh My Zsh comes with a shitload of plugins for you to take advantage of. You can
Once you spot a plugin (or several) that you'd like to use with Oh My Zsh, you'll need to enable them in the `.zshrc` file. You'll find the zshrc file in your `$HOME` directory. Open it with your favorite text editor and you'll see a spot to list all the plugins you want to load.
```shell
```sh
vi ~/.zshrc
```
For example, this might begin to look like this:
```shell
```sh
plugins=(
git
bundler
dotenv
osx
macos
rake
rbenv
ruby
@ -91,13 +91,13 @@ _Robby's theme is the default one. It's not the fanciest one. It's not the simpl
Once you find a theme that you'd like to use, you will need to edit the `~/.zshrc` file. You'll see an environment variable (all caps) in there that looks like:
```shell
```sh
ZSH_THEME="robbyrussell"
```
To use a different theme, simply change the value to match the name of your desired theme. For example:
```shell
```sh
ZSH_THEME="agnoster" # (this is one of the fancy ones)
# see https://github.com/ohmyzsh/ohmyzsh/wiki/Themes#agnoster
```
@ -112,13 +112,13 @@ In case you did not find a suitable theme for your needs, please have a look at
If you're feeling feisty, you can let the computer select one randomly for you each time you open a new terminal window.
```shell
```sh
ZSH_THEME="random" # (...please let it be pie... please be some pie..)
```
And if you want to pick random theme from a list of your favorite themes:
```shell
```sh
ZSH_THEME_RANDOM_CANDIDATES=(
"robbyrussell"
"agnoster"
@ -127,7 +127,7 @@ ZSH_THEME_RANDOM_CANDIDATES=(
If you only know which themes you don't like, you can add them similarly to an ignored list:
```shell
```sh
ZSH_THEME_RANDOM_IGNORED=(pygmalion tjkirch_mod)
```
@ -152,7 +152,7 @@ If you'd like to change the install directory with the `ZSH` environment variabl
`export ZSH=/your/path` before installing, or by setting it before the end of the install pipeline
like this:
```shell
```sh
ZSH="$HOME/.dotfiles/oh-my-zsh" sh install.sh
```
@ -162,7 +162,7 @@ If you're running the Oh My Zsh install script as part of an automated install,
flag `--unattended` to the `install.sh` script. This will have the effect of not trying to change
the default shell, and also won't run `zsh` when the installation has finished.
```shell
```sh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
```
@ -185,7 +185,7 @@ The install script also accepts these variables to allow installation of a diffe
For example:
```shell
```sh
REPO=apjanke/oh-my-zsh BRANCH=edge sh install.sh
```
@ -193,13 +193,13 @@ REPO=apjanke/oh-my-zsh BRANCH=edge sh install.sh
##### 1. Clone the repository
```shell
```sh
git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh
```
##### 2. *Optionally*, backup your existing `~/.zshrc` file
```shell
```sh
cp ~/.zshrc ~/.zshrc.orig
```
@ -207,13 +207,13 @@ cp ~/.zshrc ~/.zshrc.orig
You can create a new zsh config file by copying the template that we have included for you.
```shell
```sh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
```
##### 4. Change your default shell
```shell
```sh
chsh -s $(which zsh)
```
@ -242,23 +242,40 @@ If you would like to override the functionality of a plugin distributed with Oh
## Getting Updates
By default, you will be prompted to check for upgrades every few weeks. If you would like `oh-my-zsh` to automatically upgrade itself without prompting you, set the following in your `~/.zshrc`:
By default, you will be prompted to check for updates every 2 weeks. You can choose other update modes by adding a line to your `~/.zshrc` file, **before Oh My Zsh is loaded**:
```shell
DISABLE_UPDATE_PROMPT=true
```
1. Automatic update without confirmation prompt:
To disable automatic upgrades, set the following in your `~/.zshrc`:
```sh
zstyle ':omz:update' mode auto
```
```shell
DISABLE_AUTO_UPDATE=true
2. Just offer a reminder every few days, if there are updates available:
```sh
zstyle ':omz:update' mode reminder
```
3. To disable automatic updates entirely:
```sh
zstyle ':omz:update' mode disabled
```
NOTE: you can control how often Oh My Zsh checks for updates with the following setting:
```sh
# This will check for updates every 7 days
zstyle ':omz:update' frequency 7
# This will check for updates every time you open the terminal (not recommended)
zstyle ':omz:update' frequency 0
```
### Manual Updates
If you'd like to upgrade at any point in time (maybe someone just released a new plugin and you don't want to wait a week?) you just need to run:
If you'd like to update at any point in time (maybe someone just released a new plugin and you don't want to wait a week?) you just need to run:
```shell
```sh
omz update
```

22
SECURITY.md Normal file
View file

@ -0,0 +1,22 @@
# Security Policy
## Supported Versions
At the moment Oh My Zsh only considers the very latest commit to be supported.
We combine that with our fast response to incidents, so risk is minimized.
| Version | Supported |
|:-------------- |:------------------ |
| master | :white_check_mark: |
| other commits | :x: |
In the near future we will introduce versioning, so expect this section to change.
## Reporting a Vulnerability
If you find a vulnerability, email all the maintainers directly at:
- Robby: robby [at] planetargon.com
- Marc: hello [at] mcornella.com
**Do not open an issue or Pull Request directly**, because it might reveal the vulnerability.

View file

@ -26,6 +26,7 @@ function _omz {
'help:Usage information'
'plugin:Manage plugins'
'pr:Manage Oh My Zsh Pull Requests'
'reload:Reload the current zsh session'
'theme:Manage themes'
'update:Update Oh My Zsh'
)
@ -35,7 +36,7 @@ function _omz {
elif (( CURRENT == 3 )); then
case "$words[2]" in
changelog) local -a refs
refs=("${(@f)$(command git -C "$ZSH" for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
refs=("${(@f)$(cd "$ZSH"; command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
_describe 'command' refs ;;
plugin) subcmds=(
'disable:Disable plugin(s)'
@ -90,7 +91,8 @@ function _omz {
# NOTE: $(( CURRENT - 1 )) is the last plugin argument completely passed, i.e. that which
# has a space after them. This is to avoid removing plugins partially passed, which makes
# the completion not add a space after the completed plugin.
local -a args=(${words[4,$(( CURRENT - 1))]})
local -a args
args=(${words[4,$(( CURRENT - 1))]})
valid_plugins=(${valid_plugins:|args})
_describe 'plugin' valid_plugins ;;
@ -159,6 +161,7 @@ Available commands:
changelog Print the changelog
plugin <command> Manage plugins
pr <command> Manage Oh My Zsh Pull Requests
reload Reload the current zsh session
theme <command> Manage themes
update Update Oh My Zsh
@ -168,9 +171,12 @@ EOF
function _omz::changelog {
local version=${1:-HEAD} format=${3:-"--text"}
if ! command git -C "$ZSH" show-ref --verify refs/heads/$version &>/dev/null && \
! command git -C "$ZSH" show-ref --verify refs/tags/$version &>/dev/null && \
! command git -C "$ZSH" rev-parse --verify "${version}^{commit}" &>/dev/null; then
if (
cd "$ZSH"
! command git show-ref --verify refs/heads/$version && \
! command git show-ref --verify refs/tags/$version && \
! command git rev-parse --verify "${version}^{commit}"
) &>/dev/null; then
cat >&2 <<EOF
Usage: omz changelog [version]
@ -212,7 +218,7 @@ function _omz::plugin::disable {
fi
# Check that plugin is in $plugins
local -a dis_plugins=()
local -a dis_plugins
for plugin in "$@"; do
if [[ ${plugins[(Ie)$plugin]} -eq 0 ]]; then
_omz::log warn "plugin '$plugin' is not enabled."
@ -301,7 +307,7 @@ function _omz::plugin::enable {
fi
# Check that plugin is not in $plugins
local -a add_plugins=()
local -a add_plugins
for plugin in "$@"; do
if [[ ${plugins[(Ie)$plugin]} -ne 0 ]]; then
_omz::log warn "plugin '$plugin' is already enabled."
@ -422,10 +428,8 @@ function _omz::plugin::load {
return 1
fi
local plugins=("$@")
local plugin base has_completion=0
for plugin in $plugins; do
for plugin in "$@"; do
if [[ -d "$ZSH_CUSTOM/plugins/$plugin" ]]; then
base="$ZSH_CUSTOM/plugins/$plugin"
elif [[ -d "$ZSH/plugins/$plugin" ]]; then
@ -445,9 +449,9 @@ function _omz::plugin::load {
fi
# Check if it has completion to reload compinit
if [[ -f "$base/_$plugin" ]]; then
has_completion=1
fi
local -a comp_files
comp_files=($base/_*(N))
has_completion=$(( $#comp_files > 0 ))
# Load the plugin
if [[ -f "$base/$plugin.plugin.zsh" ]]; then
@ -598,6 +602,16 @@ function _omz::pr::test {
)
}
function _omz::reload {
# Delete current completion cache
command rm -f $_comp_dumpfile $ZSH_COMPDUMP
# Old zsh versions don't have ZSH_ARGZERO
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
# Check whether to run a login shell
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
}
function _omz::theme {
(( $# > 0 && $+functions[_omz::theme::$1] )) || {
cat >&2 <<EOF
@ -744,9 +758,9 @@ function _omz::update {
# Run update script
if [[ "$1" != --unattended ]]; then
ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" --interactive
ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" --interactive || return $?
else
ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh"
ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" || return $?
fi
# Update last updated file

View file

@ -335,7 +335,7 @@ function _omz_diag_dump_os_specific_version() {
builtin echo "OS Version: $osname $osver build $(sw_vers -buildVersion)"
;;
cygwin)
command systeminfo | command head -4 | command tail -2
command systeminfo | command head -n 4 | command tail -n 2
;;
esac

View file

@ -9,7 +9,7 @@ alias -g .....='../../../..'
alias -g ......='../../../../..'
alias -- -='cd -'
alias 1='cd -'
alias 1='cd -1'
alias 2='cd -2'
alias 3='cd -3'
alias 4='cd -4'
@ -26,7 +26,7 @@ function d () {
if [[ -n $1 ]]; then
dirs "$@"
else
dirs -v | head -10
dirs -v | head -n 10
fi
}
compdef _dirs d

View file

@ -1,7 +1,7 @@
function zsh_stats() {
fc -l 1 \
| awk '{ CMD[$2]++; count++; } END { for (a in CMD) print CMD[a] " " CMD[a]*100/count "% " a }' \
| grep -v "./" | sort -nr | head -20 | column -c3 -s " " -t | nl
| grep -v "./" | sort -nr | head -n 20 | column -c3 -s " " -t | nl
}
function uninstall_oh_my_zsh() {
@ -45,7 +45,7 @@ function takeurl() {
data="$(mktemp)"
curl -L "$1" > "$data"
tar xf "$data"
thedir="$(tar tf "$data" | head -1)"
thedir="$(tar tf "$data" | head -n 1)"
rm "$data"
cd "$thedir"
}
@ -237,12 +237,11 @@ function omz_urldecode {
tmp=${tmp:gs/\\/\\\\/}
# Handle %-escapes by turning them into `\xXX` printf escapes
tmp=${tmp:gs/%/\\x/}
local decoded
eval "decoded=\$'$tmp'"
local decoded="$(printf -- "$tmp")"
# Now we have a UTF-8 encoded string in the variable. We need to re-encode
# it if caller is in a non-UTF-8 locale.
local safe_encodings
local -a safe_encodings
safe_encodings=(UTF-8 utf8 US-ASCII)
if [[ -z ${safe_encodings[(r)$caller_encoding]} ]]; then
decoded=$(echo -E "$decoded" | iconv -f UTF-8 -t $caller_encoding)

View file

@ -51,7 +51,7 @@ function parse_git_dirty() {
FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}"
;;
esac
STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -1)
STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -n 1)
fi
if [[ -n $STATUS ]]; then
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
@ -206,7 +206,8 @@ function git_prompt_status() {
STASHED UNMERGED AHEAD BEHIND DIVERGED
)
local status_text="$(__git_prompt_git status --porcelain -b 2> /dev/null)"
local status_text
status_text="$(__git_prompt_git status --porcelain -b 2> /dev/null)"
# Don't continue on a catastrophic failure
if [[ $? -eq 128 ]]; then

View file

@ -20,16 +20,18 @@ done
# Show all 256 colors with color number
function spectrum_ls() {
setopt localoptions nopromptsubst
local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris}
for code in {000..255}; do
print -P -- "$code: $FG[$code]$ZSH_SPECTRUM_TEXT%{$reset_color%}"
print -P -- "$code: ${FG[$code]}${ZSH_SPECTRUM_TEXT}%{$reset_color%}"
done
}
# Show all 256 colors where the background is set to specific color
function spectrum_bls() {
setopt localoptions nopromptsubst
local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris}
for code in {000..255}; do
print -P -- "$code: $BG[$code]$ZSH_SPECTRUM_TEXT%{$reset_color%}"
print -P -- "$code: ${BG[$code]}${ZSH_SPECTRUM_TEXT}%{$reset_color%}"
done
}

View file

@ -7,8 +7,7 @@
# (In screen, only short_tab_title is used)
# Limited support for Apple Terminal (Terminal can't set window and tab separately)
function title {
emulate -L zsh
setopt prompt_subst
setopt localoptions nopromptsubst
# Don't set the title if inside emacs, unless using vterm
[[ -n "$INSIDE_EMACS" && "$INSIDE_EMACS" != vterm ]] && return
@ -48,13 +47,13 @@ fi
# Runs before showing the prompt
function omz_termsupport_precmd {
[[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return
title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
[[ "${DISABLE_AUTO_TITLE:-}" != true ]] || return
title "$ZSH_THEME_TERM_TAB_TITLE_IDLE" "$ZSH_THEME_TERM_TITLE_IDLE"
}
# Runs before executing the command
function omz_termsupport_preexec {
[[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return
[[ "${DISABLE_AUTO_TITLE:-}" != true ]] || return
emulate -L zsh
setopt extended_glob
@ -97,10 +96,10 @@ function omz_termsupport_preexec {
fi
# cmd name only, or if this is sudo or ssh, the next cmd
local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}
local CMD="${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}"
local LINE="${2:gs/%/%%}"
title '$CMD' '%100>...>$LINE%<<'
title "$CMD" "%100>...>${LINE}%<<"
}
autoload -Uz add-zsh-hook

View file

@ -40,7 +40,7 @@ if [[ "$DISABLE_LS_COLORS" != "true" ]]; then
fi
# enable diff color if possible.
if command diff --color . . &>/dev/null; then
if command diff --color /dev/null /dev/null &>/dev/null; then
alias diff='diff --color'
fi

View file

@ -1,8 +1,40 @@
# Protect against non-zsh execution of Oh My Zsh (use POSIX syntax here)
[ -n "$ZSH_VERSION" ] || {
# ANSI (\033[<code>m): 0: reset, 1: bold, 4: underline, 22: no bold, 24: no underline, 31: red
printf "\033[1;31mERROR:\033[22m Oh My Zsh can't be loaded from: \033[1m${0#-}\033[22m. " >&2
printf "You need to run \033[1;4mzsh\033[22;24m instead.\033[0m\n" >&2
# 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() {
# Get process tree of the current process
pid=$$; pids="$pid"
while [ ${pid-0} -ne 1 ] && ppid=$(ps -e -o pid,ppid | awk "\$1 == $pid { print \$2 }"); do
pids="$pids $pid"; pid=$ppid
done
# Show process tree
case "$(uname)" in
Linux) ps -o ppid,pid,command -f -p $pids 2>/dev/null ;;
Darwin|*) ps -o ppid,pid,command -p $pids 2>/dev/null ;;
esac
# If ps command failed, try Busybox ps
[ $? -eq 0 ] || ps -o ppid,pid,comm | awk "NR == 1 || index(\"$pids\", \$2) != 0"
}
{
shell=$(ps -o pid,comm | awk "\$1 == $$ { print \$2 }")
printf "$(omz_f 1 31)Error:$(omz_f 22) Oh My Zsh can't be loaded from: $(omz_f 1)${shell}$(omz_f 22). "
printf "You need to run $(omz_f 1)zsh$(omz_f 22) instead.$(omz_f 0)\n"
printf "$(omz_f 33)Here's the process tree:$(omz_f 22)\n\n"
omz_ptree
printf "$(omz_f 0)\n"
} >&2
return 1
}

View file

@ -8,15 +8,22 @@ To use, add `battery` to the list of plugins in your `.zshrc` file:
Then, add the `battery_pct_prompt` function to your custom theme. For example:
```
```zsh
RPROMPT='$(battery_pct_prompt) ...'
```
## Requirements
On Linux, you must have the `acpi` tool installed on your operating system.
- On Linux, you must have the `acpi` or `acpitool` commands installed on your operating system.
On Debian/Ubuntu, you can do that with `sudo apt install acpi` or `sudo apt install acpitool`.
Here's an example of how to install with apt:
```
sudo apt-get install acpi
```
- On Android (via [Termux](https://play.google.com/store/apps/details?id=com.termux)), you must have:
1. The `Termux:API` addon app installed:
[Google Play](https://play.google.com/store/apps/details?id=com.termux.api) | [F-Droid](https://f-droid.org/packages/com.termux.api/)
2. The `termux-api` package installed within termux:
```sh
pkg install termux-api
```

View file

@ -10,17 +10,17 @@
# Author: J (927589452) #
# Modified to add support for FreeBSD #
###########################################
# Author: Avneet Singh (kalsi-avneet) #
# Modified to add support for Android #
###########################################
if [[ "$OSTYPE" = darwin* ]]; then
function battery_is_charging() {
ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ Yes'
}
function battery_pct() {
pmset -g batt | grep -Eo "\d+%" | cut -d% -f1
}
function battery_pct_remaining() {
if battery_is_charging; then
echo "External Power"
@ -28,7 +28,6 @@ if [[ "$OSTYPE" = darwin* ]]; then
battery_pct
fi
}
function battery_time_remaining() {
local smart_battery_status="$(ioreg -rc "AppleSmartBattery")"
if [[ $(echo $smart_battery_status | command grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]]; then
@ -42,7 +41,6 @@ if [[ "$OSTYPE" = darwin* ]]; then
echo "∞"
fi
}
function battery_pct_prompt () {
local battery_pct color
if ioreg -rc AppleSmartBattery | command grep -q '^.*"ExternalConnected"\ =\ No'; then
@ -61,17 +59,14 @@ if [[ "$OSTYPE" = darwin* ]]; then
}
elif [[ "$OSTYPE" = freebsd* ]]; then
function battery_is_charging() {
[[ $(sysctl -n hw.acpi.battery.state) -eq 2 ]]
}
function battery_pct() {
if (( $+commands[sysctl] )); then
sysctl -n hw.acpi.battery.life
fi
}
function battery_pct_remaining() {
if ! battery_is_charging; then
battery_pct
@ -79,7 +74,6 @@ elif [[ "$OSTYPE" = freebsd* ]]; then
echo "External Power"
fi
}
function battery_time_remaining() {
local remaining_time
remaining_time=$(sysctl -n hw.acpi.battery.time)
@ -89,7 +83,6 @@ elif [[ "$OSTYPE" = freebsd* ]]; then
printf %02d:%02d $hour $minute
fi
}
function battery_pct_prompt() {
local battery_pct color
battery_pct=$(battery_pct_remaining)
@ -106,19 +99,22 @@ elif [[ "$OSTYPE" = freebsd* ]]; then
echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}"
fi
}
elif [[ "$OSTYPE" = linux* ]]; then
elif [[ "$OSTYPE" = linux-android ]] && (( ${+commands[termux-battery-status]} )); then
function battery_is_charging() {
! acpi 2>/dev/null | command grep -v "rate information unavailable" | command grep -q '^Battery.*Discharging'
termux-battery-status 2>/dev/null | command awk '/status/ { exit ($0 ~ /DISCHARGING/) }'
}
function battery_pct() {
if (( $+commands[acpi] )); then
acpi 2>/dev/null | command grep -v "rate information unavailable" | command grep -E '^Battery.*(Full|(Disc|C)harging)' | cut -f2 -d ',' | tr -cd '[:digit:]'
fi
# Sample output:
# {
# "health": "GOOD",
# "percentage": 93,
# "plugged": "UNPLUGGED",
# "status": "DISCHARGING",
# "temperature": 29.0,
# "current": 361816
# }
termux-battery-status 2>/dev/null | command awk '/percentage/ { gsub(/[,]/,""); print $2}'
}
function battery_pct_remaining() {
if ! battery_is_charging; then
battery_pct
@ -126,13 +122,72 @@ elif [[ "$OSTYPE" = linux* ]]; then
echo "External Power"
fi
}
function battery_time_remaining() {
if ! battery_is_charging; then
acpi 2>/dev/null | command grep -v "rate information unavailable" | cut -f3 -d ','
fi
}
function battery_time_remaining() { } # Not available on android
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
function battery_is_charging() {
if (( $+commands[acpitool] )); then
! acpitool 2>/dev/null | command grep -qE '^\s+Battery.*Discharging'
elif (( $+commands[acpi] )); then
! acpi 2>/dev/null | command grep -v "rate information unavailable" | command grep -q '^Battery.*Discharging'
fi
}
function battery_pct() {
if (( $+commands[acpitool] )); then
# Sample output:
# Battery #1 : Unknown, 99.55%
# Battery #2 : Discharging, 49.58%, 01:12:05
# All batteries : 62.60%, 02:03:03
local -i pct=$(acpitool 2>/dev/null | command awk -F, '
/^\s+All batteries/ {
gsub(/[^0-9.]/, "", $1)
pct=$1
exit
}
!pct && /^\s+Battery/ {
gsub(/[^0-9.]/, "", $2)
pct=$2
}
END { print pct }
')
echo $pct
elif (( $+commands[acpi] )); then
# Sample output:
# Battery 0: Discharging, 0%, rate information unavailable
# Battery 1: Full, 100%
acpi 2>/dev/null | command awk -F, '
/rate information unavailable/ { next }
/^Battery.*: /{ gsub(/[^0-9]/, "", $2); print $2; exit }
'
fi
}
function battery_pct_remaining() {
if ! battery_is_charging; then
battery_pct
else
echo "External Power"
fi
}
function battery_time_remaining() {
if ! battery_is_charging; then
acpi 2>/dev/null | command grep -v "rate information unavailable" | cut -f3 -d ','
fi
}
function battery_pct_prompt() {
local battery_pct color
battery_pct=$(battery_pct_remaining)
@ -149,7 +204,6 @@ elif [[ "$OSTYPE" = linux* ]]; then
echo "%{$fg[$color]%}${battery_pct}%%%{$reset_color%}"
fi
}
else
# Empty functions so we don't cause errors in prompts
function battery_is_charging { false }
@ -174,7 +228,7 @@ function battery_level_gauge() {
local charging_color=${BATTERY_CHARGING_COLOR:-$color_yellow}
local charging_symbol=${BATTERY_CHARGING_SYMBOL:-'⚡'}
local battery_remaining_percentage=$(battery_pct)
local -i battery_remaining_percentage=$(battery_pct)
local filled empty gauge_color
if [[ $battery_remaining_percentage =~ [0-9]+ ]]; then

View file

@ -1,8 +1,6 @@
# chucknorris
Chuck Norris fortunes plugin for oh-my-zsh. Perfectly suitable as MOTD.
**Maintainers**: [apjanke](https://github.com/apjanke) [maff](https://github.com/maff)
Chuck Norris fortunes plugin for Oh My Zsh. Perfectly suitable as MOTD.
To use it add `chucknorris` to the plugins array in you zshrc file.

View file

@ -1,28 +1,24 @@
# chucknorris: Chuck Norris fortunes
# Automatically generate or update Chuck's compiled fortune data file
# $0 must be used outside a local function. This variable name is unlikly to collide.
CHUCKNORRIS_PLUGIN_DIR=${0:h}
() {
local DIR=$CHUCKNORRIS_PLUGIN_DIR/fortunes
if [[ ! -f $DIR/chucknorris.dat ]] || [[ $DIR/chucknorris.dat -ot $DIR/chucknorris ]]; then
# For some reason, Cygwin puts strfile in /usr/sbin, which is not on the path by default
local strfile=strfile
if ! which strfile &>/dev/null && [[ -f /usr/sbin/strfile ]]; then
strfile=/usr/sbin/strfile
# %x: name of file containing code being executed
local fortunes_dir="${${(%):-%x}:h}/fortunes"
# Aliases
alias chuck="fortune -a $fortunes_dir"
alias chuck_cow="chuck | cowthink"
# Automatically generate or update Chuck's compiled fortune data file
if [[ "$fortunes_dir/chucknorris" -ot "$fortunes_dir/chucknorris.dat" ]]; then
return
fi
if which $strfile &> /dev/null; then
$strfile $DIR/chucknorris $DIR/chucknorris.dat >/dev/null
else
# For some reason, Cygwin puts strfile in /usr/sbin, which is not on the path by default
local strfile="${commands[strfile]:-/usr/sbin/strfile}"
if [[ ! -x "$strfile" ]]; then
echo "[oh-my-zsh] chucknorris depends on strfile, which is not installed" >&2
echo "[oh-my-zsh] strfile is often provided as part of the 'fortune' package" >&2
return
fi
fi
# Aliases
alias chuck="fortune -a $DIR"
alias chuck_cow="chuck | cowthink"
# Generate the compiled fortune data file
$strfile "$fortunes_dir/chucknorris" "$fortunes_dir/chucknorris.dat" >/dev/null
}
unset CHUCKNORRIS_PLUGIN_DIR

View file

@ -558,3 +558,11 @@ You know Chuck Norris' pet lizard, right? Last I heard, he was in the movie "God
%
http://chucknorrisfacts.com/ is built in Drupal because Chuck Norris knows a good CMS when he sees one.
%
Chuck Norris made the first Giraffe by uppercutting a horse.
%
Chuck Norris can hear sign language.
%
Chuck Norris make onions cry.
%
Chuck Norris doesn't shake hands, he makes them tremble.
%

View file

@ -50,13 +50,13 @@ fi
# NixOS: https://github.com/NixOS/nixpkgs/tree/master/nixos/modules/programs/command-not-found
if [[ -x /run/current-system/sw/bin/command-not-found ]]; then
command_not_found_handler() {
/run/current-system/sw/bin/command-not-found -- "$@"
/run/current-system/sw/bin/command-not-found "$@"
}
fi
# Termux: https://github.com/termux/command-not-found
if [[ -x /data/data/com.termux/files/usr/libexec/termux/command-not-found ]]; then
command_not_found_handler() {
/data/data/com.termux/files/usr/libexec/termux/command-not-found -- "$1"
/data/data/com.termux/files/usr/libexec/termux/command-not-found "$1"
}
fi

View file

@ -12,19 +12,27 @@ plugins=(... dirhistory)
| Shortcut | Description |
|-----------------------------------|-----------------------------------------------------------|
| <kbd>alt</kbd> + <kbd>left</kbd> | Go to previous directory |
| <kbd>alt</kbd> + <kbd>right</kbd> | Undo <kbd>alt</kbd> + <kbd>left</kbd> |
| <kbd>alt</kbd> + <kbd>up</kbd> | Move into the parent directory |
| <kbd>alt</kbd> + <kbd>down</kbd> | Move into the first child directory by alphabetical order |
| <kbd>Alt</kbd> + <kbd>Left</kbd> | Go to previous directory |
| <kbd>Alt</kbd> + <kbd>Right</kbd> | Go to next directory |
| <kbd>Alt</kbd> + <kbd>Up</kbd> | Move into the parent directory |
| <kbd>Alt</kbd> + <kbd>Down</kbd> | Move into the first child directory by alphabetical order |
NOTE: some terminals might override the ALT+Arrows key bindings (Windows Terminal, for example).
If these don't work check your terminal settings and change them to a different keyboard shortcut.
**For macOS: use the Option key (<kbd></kbd>) instead of <kbd>Alt</kbd>**.
> NOTE: some terminals might override the <kbd>Alt</kbd> + Arrows key bindings (e.g. Windows Terminal).
> If these don't work check your terminal settings and change them to a different keyboard shortcut.
## Usage
This plugin allows you to navigate the history of previous current-working-directories using ALT-LEFT and ALT-RIGHT. ALT-LEFT moves back to directories that the user has changed to in the past, and ALT-RIGHT undoes ALT-LEFT. MAC users may alternately use OPT-LEFT and OPT-RIGHT.
This plugin allows you to navigate the history of previous working directories using <kbd>Alt</kbd> + <kbd>Left</kbd>
and <kbd>Alt</kbd> + <kbd>Right</kbd>. <kbd>Alt</kbd> + <kbd>Left</kbd> moves to past directories, and
<kbd>Alt</kbd> + <kbd>Right</kbd> goes back to recent directories.
Also, navigate directory **hierarchy** using ALT-UP and ALT-DOWN. (mac keybindings not yet implemented). ALT-UP moves to higher hierarchy (shortcut for 'cd ..'). ALT-DOWN moves into the first directory found in alphabetical order (useful to navigate long empty directories e.g. java packages)
**NOTE: the maximum directory history size is 30.**
You can also navigate **directory hierarchies** using <kbd>Alt</kbd> + <kbd>Up</kbd> and <kbd>Alt</kbd> + <kbd>Down</kbd>.
<kbd>Alt</kbd> + <kbd>Up</kbd> moves to the parent directory, while <kbd>Alt</kbd> + <kbd>Down</kbd> moves into the first
child directory found in alphabetical order (useful to navigate long empty directories, e.g. Java packages).
For example, if the shell was started, and the following commands were entered:
@ -35,8 +43,20 @@ cd share
cd doc
```
Then entering ALT-LEFT at the prompt would change directory from /usr/share/doc to /usr/share, then if pressed again to /usr/, then ~. If ALT-RIGHT were pressed the directory would be changed to /usr/ again.
the directory stack (`dirs -v`) would look like this:
After that, ALT-DOWN will probably go to /usr/bin (depends on your /usr structure), ALT-UP will return to /usr, then ALT-UP will get you to /
```console
$ dirs -v
0 /usr/share/doc
1 /usr/share
2 /usr
3 ~
```
**Currently the max history size is 30**. The navigation should work for xterm, PuTTY xterm mode, GNU screen, and on MAC with alternate keys as mentioned above.
then entering <kbd>Alt</kbd> + <kbd>Left</kbd> at the prompt would change directory from `/usr/share/doc` to `/usr/share`,
then if pressed again to `/usr`, then `~`. If <kbd>Alt</kbd> + <kbd>Right</kbd> were pressed the directory would be changed
to `/usr` again.
After that, <kbd>Alt</kbd> + <kbd>Down</kbd> will probably go to `/usr/bin` if `bin` is the first directory in alphabetical
order (depends on your `/usr` folder structure). <kbd>Alt</kbd> + <kbd>Up</kbd> will return to `/usr`, and once more will get
you to the root folder (`/`).

View file

@ -1,7 +1,7 @@
##
# Navigate directory history using ALT-LEFT and ALT-RIGHT. ALT-LEFT moves back to directories
##
# Navigate directory history using ALT-LEFT and ALT-RIGHT. ALT-LEFT moves back to directories
# that the user has changed to in the past, and ALT-RIGHT undoes ALT-LEFT.
#
#
# Navigate directory hierarchy using ALT-UP and ALT-DOWN.
# ALT-UP moves to higher hierarchy (cd ..)
# ALT-DOWN moves into the first directory found in alphabetical order
@ -14,25 +14,25 @@ export dirhistory_future
export DIRHISTORY_SIZE=30
# Pop the last element of dirhistory_past.
# Pass the name of the variable to return the result in.
# Pop the last element of dirhistory_past.
# Pass the name of the variable to return the result in.
# Returns the element if the array was not empty,
# otherwise returns empty string.
function pop_past() {
eval "$1='$dirhistory_past[$#dirhistory_past]'"
eval "$1=${(q)dirhistory_past[$#dirhistory_past]}"
if [[ $#dirhistory_past -gt 0 ]]; then
dirhistory_past[$#dirhistory_past]=()
fi
}
function pop_future() {
eval "$1='$dirhistory_future[$#dirhistory_future]'"
eval "$1=${(q)dirhistory_future[$#dirhistory_future]}"
if [[ $#dirhistory_future -gt 0 ]]; then
dirhistory_future[$#dirhistory_future]=()
fi
}
# Push a new element onto the end of dirhistory_past. If the size of the array
# Push a new element onto the end of dirhistory_past. If the size of the array
# is >= DIRHISTORY_SIZE, the array is shifted
function push_past() {
if [[ $#dirhistory_past -ge $DIRHISTORY_SIZE ]]; then
@ -76,7 +76,7 @@ function dirhistory_back() {
local d=""
# Last element in dirhistory_past is the cwd.
pop_past cw
pop_past cw
if [[ "" == "$cw" ]]; then
# Someone overwrote our variable. Recover it.
dirhistory_past=($PWD)
@ -121,40 +121,35 @@ function dirhistory_zle_dirhistory_future() {
}
zle -N dirhistory_zle_dirhistory_back
# xterm in normal mode
bindkey "\e[3D" dirhistory_zle_dirhistory_back
bindkey "\e[1;3D" dirhistory_zle_dirhistory_back
# Terminal.app
if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then
bindkey "^[b" dirhistory_zle_dirhistory_back
bindkey "\e[3D" dirhistory_zle_dirhistory_back # xterm in normal mode
bindkey "\e[1;3D" dirhistory_zle_dirhistory_back # xterm in normal mode
bindkey "\e\e[D" dirhistory_zle_dirhistory_back # Putty
bindkey "\eO3D" dirhistory_zle_dirhistory_back # GNU screen
case "$TERM_PROGRAM" in
iTerm.app) bindkey "^[^[[D" dirhistory_zle_dirhistory_back ;; # iTerm2
Apple_Terminal) bindkey "^[b" dirhistory_zle_dirhistory_back ;; # Terminal.app
esac
if (( ${+terminfo[kcub1]} )); then
bindkey "^[${terminfo[kcub1]}" dirhistory_zle_dirhistory_back # urxvt
fi
# iTerm2
if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
bindkey "^[^[[D" dirhistory_zle_dirhistory_back
fi
# Putty:
bindkey "\e\e[D" dirhistory_zle_dirhistory_back
# GNU screen:
bindkey "\eO3D" dirhistory_zle_dirhistory_back
zle -N dirhistory_zle_dirhistory_future
bindkey "\e[3C" dirhistory_zle_dirhistory_future
bindkey "\e[1;3C" dirhistory_zle_dirhistory_future
# Terminal.app
if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then
bindkey "^[f" dirhistory_zle_dirhistory_future
bindkey "\e[3C" dirhistory_zle_dirhistory_future # xterm in normal mode
bindkey "\e[1;3C" dirhistory_zle_dirhistory_future # xterm in normal mode
bindkey "\e\e[C" dirhistory_zle_dirhistory_future # Putty
bindkey "\eO3C" dirhistory_zle_dirhistory_future # GNU screen
case "$TERM_PROGRAM" in
iTerm.app) bindkey "^[^[[C" dirhistory_zle_dirhistory_future ;; # iTerm2
Apple_Terminal) bindkey "^[f" dirhistory_zle_dirhistory_future ;; # Terminal.app
esac
if (( ${+terminfo[kcuf1]} )); then
bindkey "^[${terminfo[kcuf1]}" dirhistory_zle_dirhistory_future # urxvt
fi
# iTerm2
if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
bindkey "^[^[[C" dirhistory_zle_dirhistory_future
fi
bindkey "\e\e[C" dirhistory_zle_dirhistory_future
bindkey "\eO3C" dirhistory_zle_dirhistory_future
#
#
# HIERARCHY Implemented in this section, in case someone wants to split it to another plugin if it clashes bindings
#
#
# Move up in hierarchy
function dirhistory_up() {
@ -181,22 +176,27 @@ function dirhistory_zle_dirhistory_down() {
}
zle -N dirhistory_zle_dirhistory_up
# xterm in normal mode
bindkey "\e[3A" dirhistory_zle_dirhistory_up
bindkey "\e[1;3A" dirhistory_zle_dirhistory_up
if [[ "$TERM_PROGRAM" == "Apple_Terminal" || "$TERM_PROGRAM" == "iTerm.app" ]]; then
bindkey "^[[A" dirhistory_zle_dirhistory_up
bindkey "\e[3A" dirhistory_zle_dirhistory_up # xterm in normal mode
bindkey "\e[1;3A" dirhistory_zle_dirhistory_up # xterm in normal mode
bindkey "\e\e[A" dirhistory_zle_dirhistory_up # Putty
bindkey "\eO3A" dirhistory_zle_dirhistory_up # GNU screen
case "$TERM_PROGRAM" in
iTerm.app) bindkey "^[^[[A" dirhistory_zle_dirhistory_up ;; # iTerm2
Apple_Terminal) bindkey "^[[A" dirhistory_zle_dirhistory_up ;; # Terminal.app
esac
if (( ${+terminfo[kcuu1]} )); then
bindkey "^[${terminfo[kcuu1]}" dirhistory_zle_dirhistory_up # urxvt
fi
# Putty:
bindkey "\e\e[A" dirhistory_zle_dirhistory_up
# GNU screen:
bindkey "\eO3A" dirhistory_zle_dirhistory_up
zle -N dirhistory_zle_dirhistory_down
bindkey "\e[3B" dirhistory_zle_dirhistory_down
bindkey "\e[1;3B" dirhistory_zle_dirhistory_down
if [[ "$TERM_PROGRAM" == "Apple_Terminal" || "$TERM_PROGRAM" == "iTerm.app" ]]; then
bindkey "^[[B" dirhistory_zle_dirhistory_down
bindkey "\e[3B" dirhistory_zle_dirhistory_down # xterm in normal mode
bindkey "\e[1;3B" dirhistory_zle_dirhistory_down # xterm in normal mode
bindkey "\e\e[B" dirhistory_zle_dirhistory_down # Putty
bindkey "\eO3B" dirhistory_zle_dirhistory_down # GNU screen
case "$TERM_PROGRAM" in
iTerm.app) bindkey "^[^[[B" dirhistory_zle_dirhistory_down ;; # iTerm2
Apple_Terminal) bindkey "^[[B" dirhistory_zle_dirhistory_down ;; # Terminal.app
esac
if (( ${+terminfo[kcud1]} )); then
bindkey "^[${terminfo[kcud1]}" dirhistory_zle_dirhistory_down # urxvt
fi
bindkey "\e\e[B" dirhistory_zle_dirhistory_down
bindkey "\eO3B" dirhistory_zle_dirhistory_down

View file

@ -121,12 +121,6 @@ __docker-compose_subcommand() {
'--parallel[Build images in parallel.]' \
'*:services:__docker-compose_services_from_build' && ret=0
;;
(bundle)
_arguments \
$opts_help \
'--push-images[Automatically push images for any services which have a `build` option specified.]' \
'(--output -o)'{--output,-o}'[Path to write the bundle file to. Defaults to "<project name>.dab".]:file:_files' && ret=0
;;
(config)
_arguments \
$opts_help \
@ -290,7 +284,7 @@ __docker-compose_subcommand() {
(up)
_arguments \
$opts_help \
'(--abort-on-container-exit)-d[Detached mode: Run containers in the background, print new container names. Incompatible with --abort-on-container-exit.]' \
'(--abort-on-container-exit)-d[Detached mode: Run containers in the background, print new container names. Incompatible with --abort-on-container-exit and --attach-dependencies.]' \
$opts_no_color \
$opts_no_deps \
$opts_force_recreate \
@ -298,6 +292,7 @@ __docker-compose_subcommand() {
$opts_no_build \
"(--no-build)--build[Build images before starting containers.]" \
"(-d)--abort-on-container-exit[Stops all containers if any container was stopped. Incompatible with -d.]" \
"(-d)--attach-dependencies[Attach to dependent containers. Incompatible with -d.]" \
'(-t --timeout)'{-t,--timeout}"[Use this timeout in seconds for container shutdown when attached or when containers are already running. (default: 10)]:seconds: " \
'--scale[SERVICE=NUM Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present.]:service scale SERVICE=NUM: ' \
'--exit-code-from=[Return the exit code of the selected service container. Implies --abort-on-container-exit]:service:__docker-compose_services' \
@ -341,11 +336,13 @@ _docker-compose() {
'(- :)'{-h,--help}'[Get help]' \
'*'{-f,--file}"[${file_description}]:file:_files -g '*.yml'" \
'(-p --project-name)'{-p,--project-name}'[Specify an alternate project name (default: directory name)]:project name:' \
'--env-file[Specify an alternate environment file (default: .env)]:env-file:_files' \
"--compatibility[If set, Compose will attempt to convert keys in v3 files to their non-Swarm equivalent]" \
'(- :)'{-v,--version}'[Print version and exit]' \
'--verbose[Show more output]' \
'--log-level=[Set log level]:level:(DEBUG INFO WARNING ERROR CRITICAL)' \
'--no-ansi[Do not print ANSI control characters]' \
'--ansi=[Control when to print ANSI control characters]:when:(never always auto)' \
'(-H --host)'{-H,--host}'[Daemon socket to connect to]:host:' \
'--tls[Use TLS; implied by --tlsverify]' \
'--tlscacert=[Trust certs signed only by this CA]:ca path:' \
@ -359,6 +356,7 @@ _docker-compose() {
local -a relevant_compose_flags relevant_compose_repeatable_flags relevant_docker_flags compose_options docker_options
relevant_compose_flags=(
"--env-file"
"--file" "-f"
"--host" "-H"
"--project-name" "-p"

View file

@ -1,28 +1,24 @@
# Authors:
# https://github.com/tristola
#
# Docker-compose related zsh aliases
# support Compose v2 as docker CLI plugin
DOCKER_CONTEXT=default command docker compose &>/dev/null \
&& dccmd='docker compose' \
|| dccmd='docker-compose'
# Aliases ###################################################################
alias dco="$dccmd"
alias dcb="$dccmd build"
alias dce="$dccmd exec"
alias dcps="$dccmd ps"
alias dcrestart="$dccmd restart"
alias dcrm="$dccmd rm"
alias dcr="$dccmd run"
alias dcstop="$dccmd stop"
alias dcup="$dccmd up"
alias dcupb="$dccmd up --build"
alias dcupd="$dccmd up -d"
alias dcdn="$dccmd down"
alias dcl="$dccmd logs"
alias dclf="$dccmd logs -f"
alias dcpull="$dccmd pull"
alias dcstart="$dccmd start"
alias dck="$dccmd kill"
# Use dco as alias for docker-compose, since dc on *nix is 'dc - an arbitrary precision calculator'
# https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html
alias dco='docker-compose'
alias dcb='docker-compose build'
alias dce='docker-compose exec'
alias dcps='docker-compose ps'
alias dcrestart='docker-compose restart'
alias dcrm='docker-compose rm'
alias dcr='docker-compose run'
alias dcstop='docker-compose stop'
alias dcup='docker-compose up'
alias dcupb='docker-compose up --build'
alias dcupd='docker-compose up -d'
alias dcdn='docker-compose down'
alias dcl='docker-compose logs'
alias dclf='docker-compose logs -f'
alias dcpull='docker-compose pull'
alias dcstart='docker-compose start'
alias dck='docker-compose kill'
unset dccmd

View file

@ -20,7 +20,9 @@ function setup_using_base_dir() {
done
if [[ -z "${fzf_base}" ]]; then
if (( ${+commands[brew]} )) && dir="$(brew --prefix fzf 2>/dev/null)"; then
if (( ${+commands[fzf-share]} )) && dir="$(fzf-share)" && [[ -d "${dir}" ]]; then
fzf_base="${dir}"
elif (( ${+commands[brew]} )) && dir="$(brew --prefix fzf 2>/dev/null)"; then
if [[ -d "${dir}" ]]; then
fzf_base="${dir}"
fi

View file

@ -47,6 +47,7 @@ plugins=(... git)
| gcb | git checkout -b |
| gcf | git config --list |
| gcl | git clone --recurse-submodules |
| gccd | git clone --recurse-submodules "$@" && cd "$(basename $_ .git)" |
| gclean | git clean -id |
| gpristine | git reset --hard && git clean -dffx |
| gcm | git checkout $(git_main_branch) |
@ -66,7 +67,7 @@ plugins=(... git)
| gds | git diff --staged |
| gdt | git diff-tree --no-commit-id --name-only -r |
| gdnolock | git diff $@ ":(exclude)package-lock.json" ":(exclude)&ast;.lock" |
| gdu | git diff @{u} |
| gdup | git diff @{upstream} |
| gdv | git diff -w $@ \| view - |
| gdw | git diff --word-diff |
| gf | git fetch |
@ -90,8 +91,8 @@ plugins=(... git)
| gignore | git update-index --assume-unchanged |
| gignored | git ls-files -v \| grep "^[[:lower:]]" |
| git-svn-dcommit-push | git svn dcommit && git push github $(git_main_branch):svntrunk |
| gk | gitk --all --branches |
| gke | gitk --all $(git log -g --pretty=%h) |
| gk | gitk --all --branches &! |
| gke | gitk --all $(git log -g --pretty=%h) &! |
| gl | git pull |
| glg | git log --stat |
| glgp | git log --stat -p |
@ -168,6 +169,8 @@ plugins=(... git)
| gsu | git submodule update |
| gsw | git switch |
| gswc | git switch -c |
| gswm | git switch $(git_main_branch) |
| gswd | git switch $(git_develop_branch) |
| gts | git tag -s |
| gtv | git tag \| sort -V |
| gtl | gtl(){ git tag --sort=-v:refname -n -l ${1}* }; noglob gtl |

View file

@ -97,6 +97,13 @@ alias gcas='git commit -a -s'
alias gcasm='git commit -a -s -m'
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 -id'
alias gpristine='git reset --hard && git clean -dffx'
@ -119,7 +126,7 @@ 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 gdu='git diff @{u}'
alias gdup='git diff @{upstream}'
alias gdw='git diff --word-diff'
function gdnolock() {
@ -201,8 +208,8 @@ 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 -g --pretty=%h)'
alias gk='\gitk --all --branches &!'
alias gke='\gitk --all $(git log -g --pretty=%h) &!'
alias gl='git pull'
alias glg='git log --stat'
@ -288,6 +295,8 @@ alias gstall='git stash --all'
alias gsu='git submodule update'
alias gsw='git switch'
alias gswc='git switch -c'
alias gswm='git switch $(git_main_branch)'
alias gswd='git switch $(git_develop_branch)'
alias gts='git tag -s'
alias gtv='git tag | sort -V'

View file

@ -2,7 +2,7 @@
Enables [GPG's gpg-agent](https://www.gnupg.org/documentation/manuals/gnupg/) if it is not running.
To use it, add gpg-agent to the plugins array of your zshrc file:
To use it, add `gpg-agent` to the plugins array of your zshrc file:
```zsh
plugins=(... gpg-agent)

View file

@ -1,16 +1,17 @@
# Enable gpg-agent if it is not running-
# --use-standard-socket will work from version 2 upwards
AGENT_SOCK=$(gpgconf --list-dirs | grep agent-socket | cut -d : -f 2)
if [[ ! -S $AGENT_SOCK ]]; then
gpg-agent --daemon --use-standard-socket &>/dev/null
fi
export GPG_TTY=$TTY
# Set SSH to use gpg-agent if it's enabled
GNUPGCONFIG="${GNUPGHOME:-"$HOME/.gnupg"}/gpg-agent.conf"
if [[ -r $GNUPGCONFIG ]] && command grep -q enable-ssh-support "$GNUPGCONFIG"; then
export SSH_AUTH_SOCK="$AGENT_SOCK.ssh"
# Fix for passphrase prompt on the correct tty
# See https://www.gnupg.org/documentation/manuals/gnupg/Agent-Options.html#option-_002d_002denable_002dssh_002dsupport
function _gpg-agent_update-tty_preexec {
gpg-connect-agent updatestartuptty /bye &>/dev/null
}
autoload -U add-zsh-hook
add-zsh-hook preexec _gpg-agent_update-tty_preexec
# If enable-ssh-support is set, fix ssh agent integration
if [[ $(gpgconf --list-options gpg-agent | awk -F: '$1=="enable-ssh-support" {print $10}') = 1 ]]; then
unset SSH_AGENT_PID
if [[ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]]; then
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
fi
fi

View file

@ -1,14 +1,18 @@
if ! (( $+commands[curl] )); then
echo "hitokoto plugin needs curl to work" >&2
return
echo "hitokoto plugin needs curl to work" >&2
return
fi
function hitokoto {
emulate -L zsh
Q=$(curl -s --connect-timeout 2 "https://v1.hitokoto.cn" | jq -j '.hitokoto+"\t"+.from')
setopt localoptions nopromptsubst
TXT=$(echo "$Q" | awk -F '\t' '{print $1}')
WHO=$(echo "$Q" | awk -F '\t' '{print $2}')
# Get hitokoto data
local -a data
data=("${(ps:\n:)"$(command curl -s --connect-timeout 2 "https://v1.hitokoto.cn" | command jq -j '.hitokoto+"\n"+.from')"}")
[[ -n "$WHO" && -n "$TXT" ]] && print -P "%F{3}${WHO}%f: “%F{5}${TXT}%f”"
# Exit if could not fetch hitokoto
[[ -n "$data" ]] || return 0
local quote="${data[1]}" author="${data[2]}"
print -P "%F{3}${author}%f: “%F{5}${quote}%f”"
}

View file

@ -7,7 +7,7 @@ if [[ -n "$JSONTOOLS_METHOD" ]]; then
fi
# If method undefined, find the first one that is installed
if [[ ! -v JSONTOOLS_METHOD ]]; then
if [[ -z "$JSONTOOLS_METHOD" ]]; then
for JSONTOOLS_METHOD in node python ruby; do
# If method found, break out of loop
(( $+commands[$JSONTOOLS_METHOD] )) && break
@ -16,7 +16,7 @@ if [[ ! -v JSONTOOLS_METHOD ]]; then
done
# If no methods were found, exit the plugin
[[ -v JSONTOOLS_METHOD ]] || return 1
[[ -n "$JSONTOOLS_METHOD" ]] || return 1
fi
# Define json tools for each method

63
plugins/macos/README.md Normal file
View file

@ -0,0 +1,63 @@
# MacOS plugin
This plugin provides a few utilities to make it more enjoyable on macOS (previously named OSX).
To start using it, add the `macos` plugin to your plugins array in `~/.zshrc`:
```zsh
plugins=(... macos)
```
Original author: [Sorin Ionescu](https://github.com/sorin-ionescu)
## Commands
| Command | Description |
| :------------ | :------------------------------------------------------- |
| `tab` | Open the current directory in a new tab |
| `split_tab` | Split the current terminal tab horizontally |
| `vsplit_tab` | Split the current terminal tab vertically |
| `ofd` | Open the current directory in a Finder window |
| `pfd` | Return the path of the frontmost Finder window |
| `pfs` | Return the current Finder selection |
| `cdf` | `cd` to the current Finder directory |
| `pushdf` | `pushd` to the current Finder directory |
| `pxd` | Return the current Xcode project directory |
| `cdx` | `cd` to the current Xcode project directory |
| `quick-look` | Quick-Look a specified file |
| `man-preview` | Open a specified man page in Preview app |
| `showfiles` | Show hidden files in Finder |
| `hidefiles` | Hide the hidden files in Finder |
| `itunes` | _DEPRECATED_. Use `music` from macOS Catalina on |
| `music` | Control Apple Music. Use `music -h` for usage details |
| `spotify` | Control Spotify and search by artist, album, track… |
| `rmdsstore` | Remove .DS_Store files recursively in a directory |
| `btrestart` | Restart the Bluetooth daemon |
| `freespace` | Erases purgeable disk space with 0s on the selected disk |
## Acknowledgements
This application makes use of the following third party scripts:
[shpotify](https://github.com/hnarayanan/shpotify)
Copyright (c) 20122019 [Harish Narayanan](https://harishnarayanan.org/).
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,3 +1,9 @@
# Check if 'osx' is still in the plugins list and prompt to change to 'macos'
if [[ -n "${plugins[(r)osx]}" ]]; then
print ${(%):-"%F{yellow}The \`osx\` plugin is deprecated and has been renamed to \`macos\`."}
print ${(%):-"Please update your .zshrc to use the \`%Bmacos%b\` plugin instead.%f"}
fi
# Open the current directory in a Finder window
alias ofd='open_command $PWD'
@ -11,7 +17,7 @@ function btrestart() {
sudo kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
}
function _omz_osx_get_frontmost_app() {
function _omz_macos_get_frontmost_app() {
osascript 2>/dev/null <<EOF
tell application "System Events"
name of first item of (every process whose frontmost is true)
@ -24,7 +30,7 @@ function tab() {
local command="cd \\\"$PWD\\\"; clear"
(( $# > 0 )) && command="${command}; $*"
local the_app=$(_omz_osx_get_frontmost_app)
local the_app=$(_omz_macos_get_frontmost_app)
if [[ "$the_app" == 'Terminal' ]]; then
# Discarding stdout to quash "tab N of window id XXX" output
@ -77,7 +83,7 @@ function vsplit_tab() {
local command="cd \\\"$PWD\\\"; clear"
(( $# > 0 )) && command="${command}; $*"
local the_app=$(_omz_osx_get_frontmost_app)
local the_app=$(_omz_macos_get_frontmost_app)
if [[ "$the_app" == 'iTerm' ]]; then
osascript <<EOF
@ -125,7 +131,7 @@ function split_tab() {
local command="cd \\\"$PWD\\\"; clear"
(( $# > 0 )) && command="${command}; $*"
local the_app=$(_omz_osx_get_frontmost_app)
local the_app=$(_omz_macos_get_frontmost_app)
if [[ "$the_app" == 'iTerm' ]]; then
osascript 2>/dev/null <<EOF
@ -233,6 +239,29 @@ function rmdsstore() {
find "${@:-.}" -type f -name .DS_Store -delete
}
# Erases purgeable disk space with 0s on the selected disk
function freespace(){
if [[ -z "$1" ]]; then
echo "Usage: $0 <disk>"
echo "Example: $0 /dev/disk1s1"
echo
echo "Possible disks:"
df -h | awk 'NR == 1 || /^\/dev\/disk/'
return 1
fi
echo "Cleaning purgeable files from disk: $1 ...."
diskutil secureErase freespace 0 $1
}
_freespace() {
local -a disks
disks=("${(@f)"$(df | awk '/^\/dev\/disk/{ printf $1 ":"; for (i=9; i<=NF; i++) printf $i FS; print "" }')"}")
_describe disks disks
}
compdef _freespace freespace
# Music / iTunes control function
source "${0:h:A}/music"

View file

@ -0,0 +1 @@
macos.plugin.zsh

View file

@ -30,7 +30,8 @@ plugins=(... mercurial)
| `hgl` | `hg pull -u` |
| `hglr` | `hg pull --rebase` |
| `hgo` | `hg outgoing` |
| `hglg` | `hg log --stat -v` |
| `hglgp`| `hg log --stat -p -v` |
## Prompt usage
- Switch to a theme which uses `hg_prompt_info`

View file

@ -17,6 +17,8 @@ alias hgi='hg incoming'
alias hgl='hg pull -u'
alias hglr='hg pull --rebase'
alias hgo='hg outgoing'
alias hglg='hg log --stat -v'
alias hglgp='hg log --stat -p -v'
function in_hg() {
if $(hg branch > /dev/null 2>&1); then

View file

@ -9,11 +9,11 @@ plugins=(... mix)
```
## Supported Task Types
| Task Type | Documentation |
|-------------------------|----------------------------------------------------------|
| Elixir | [Elixir Lang](https://elixir-lang.org/) |
| Phoenix v1.2.1 and below| [Phoenix](https://hexdocs.pm/phoenix/1.2.1/Phoenix.html) |
| Phoenix v1.3.0 and above| [Phoenix](https://hexdocs.pm/phoenix/Phoenix.html) |
| Ecto | [Ecto](https://hexdocs.pm/ecto/Ecto.html) |
| Hex | [Hex](https://hex.pm/) |
| Nerves | [Nerves](https://nerves-project.org/) |
| Task Type | Documentation |
|--------------------------|----------------------------------------------------------|
| Elixir | [Elixir Lang](https://elixir-lang.org/) |
| Phoenix v1.2.1 and below | [Phoenix](https://hexdocs.pm/phoenix/1.2.1/Phoenix.html) |
| Phoenix v1.3.0 and above | [Phoenix](https://hexdocs.pm/phoenix/Phoenix.html) |
| Ecto | [Ecto](https://hexdocs.pm/ecto/Ecto.html) |
| Hex | [Hex](https://hex.pm/) |
| Nerves | [Nerves](https://nerves-project.org/) |

View file

@ -5,8 +5,10 @@
local -a _1st_arguments
_1st_arguments=(
'app.config:Configures all registered apps'
'app.start:Start all registered apps'
'archive:List all archives'
'app.tree:Prints the application tree'
'archive:Lists installed archives'
'archive.build:Archive this project into a .ez file'
'archive.install:Install an archive locally'
'archive.uninstall:Uninstall archives'
@ -18,6 +20,7 @@ _1st_arguments=(
"deps.clean:Remove the given dependencies' files"
'deps.compile:Compile dependencies'
'deps.get:Get all out of date dependencies'
'deps.tree:Prints the dependency tree'
'deps.unlock:Unlock the given dependencies'
'deps.update:Update the given dependencies'
'do:Executes the tasks separated by comma'
@ -30,27 +33,39 @@ _1st_arguments=(
'ecto.migrate:Runs Ecto migration'
'ecto.migrations:Displays the up / down migration status'
'ecto.rollback:Reverts applied migrations'
'escript:Lists installed escripts'
'escript.build:Builds an escript for the project'
'escript.install:Installs an escript locally'
'escript.uninstall:Uninstalls escripts'
'firmware:Nerves - Build a firmware image for the selected target platform'
'firmware.burn:Nerves - Writes the generated firmware image to an attached SDCard or file'
'firmware.image:Nerves - Create a firmware image file that can be copied byte-for-byte'
'format:Formats the given files and patterns'
'help:Print help information for tasks'
'hex:Print hex help information'
'hex.config:Read or update hex config'
'hex.docs:Publish docs for package'
'hex.audit:Shows retired Hex deps for the current project'
'hex.build:Builds a new package version locally'
'hex.config:Reads, updates or deletes local Hex config'
'hex.docs:Fetches or opens documentation of a package'
'hex.info:Print hex information'
'hex.organization:Manages Hex.pm organizations'
'hex.key:Hex API key tasks'
'hex.outdated:Shows outdated hex deps for the current project'
'hex.owner:Hex package ownership tasks'
'hex.outdated:Shows outdated Hex deps for the current project'
'hex.owner:Manages Hex package ownership'
'hex.package:Fetches or diffs packages'
'hex.publish:Publish a new package version'
'hex.registry:Manages local Hex registries'
'hex.repo:Manages Hex repositories'
'hex.retire:Retires a package version'
'hex.search:Search for package names'
'hex.user:Hex user tasks'
'hex.sponsor:Show Hex packages accepting sponsorships'
'hex.user:Manages your Hex user account'
'loadconfig:Loads and persists the given configuration'
'local:List local tasks'
'local.hex:Install hex locally'
'local.phoenix:Updates Phoenix locally'
'local.phx:Updates the Phoenix project generator locally'
'local.public_keys:Manages public keys'
'local.rebar:Install rebar locally'
'nerves.artifact:Create an artifact for a specified Nerves package'
'nerves.artifact.get:Nerves get artifacts'
@ -69,21 +84,33 @@ _1st_arguments=(
'phoenix.server:Starts applications and their servers'
'phx.digest:Digests and compresses static files'
'phx.digest.clean:Removes old versions of static assets.'
'phx.gen.auth:Generates authentication logic for a resource'
'phx.gen.cert:Generates a self-signed certificate for HTTPS testing'
'phx.gen.channel:Generates a Phoenix channel'
'phx.gen.context:Generates a context with functions around an Ecto schema'
'phx.gen.embedded:Generates an embedded Ecto schema file'
'phx.gen.html:Generates controller, views, and context for an HTML resource'
'phx.gen.json:Generates controller, views, and context for a JSON resource'
'phx.gen.live:Generates LiveView, templates, and context for a resource'
'phx.gen.notifier:Generates a notifier that delivers emails by default'
'phx.gen.presence:Generates a Presence tracker'
'phx.gen.schema:Generates an Ecto schema and migration file'
'phx.gen.secret:Generates a secret'
'phx.new:Creates a new Phoenix v1.3.0 application'
'phx.gen.socket:Generates a Phoenix socket handler'
'phx.new:Creates a new Phoenix application'
'phx.new.ecto:Creates a new Ecto project within an umbrella project'
'phx.new.web:Creates a new Phoenix web project within an umbrella project'
'phx.routes:Prints all routes'
'phx.server:Starts applications and their servers'
'profile.cprof:Profiles the given file or expression with cprof'
'profile.eprof:Profiles the given file or expression with eprof'
'profile.fprof:Profiles the given file or expression with fprof'
'release:Assembles a self-contained release'
'release.init:Generates sample files for releases'
'run:Run the given file or expression'
"test:Run a project's tests"
'test.coverage:Build report from exported test coverage'
'xref:Prints cross reference information'
'--help:Describe available tasks'
'--version:Prints the Elixir version information'
)
@ -93,7 +120,7 @@ __task_list ()
local expl
declare -a tasks
tasks=(app.start archive archive.build archive.install archive.uninstall clean cmd compile compile.protocols deps deps.clean deps.compile deps.get deps.unlock deps.update do escript.build format help hex hex.config hex.docs hex.info hex.key hex.outdated hex.owner hex.publish hex.search hex.user loadconfig local local.hex local.rebar new phoenix.digest phoenix.gen.channel phoenix.gen.html phoenix.gen.json phoenix.gen.model phoenix.gen.secret phoenix.new phoenix.routes phoenix.server phx.digest phx.digest.clean phx.gen.channel phx.gen.context phx.gen.embedded phx.gen.html phx.gen.json phx.gen.presence phx.gen.schema phx.gen.secret phx.new phx.new.ecto phx.new.web phx.routes phx.server run test)
tasks=(app.config app.start app.tree archive archive.build archive.install archive.uninstall clean cmd compile compile.protocols deps deps.clean deps.compile deps.get deps.tree deps.unlock deps.update do ecto.create ecto.drop ecto.dump ecto.gen.migration ecto.gen.repo ecto.load ecto.migrate ecto.migrations ecto.rollback escript escript.build escript.install escript.uninstall firmware firmware.burn firmware.image format help hex hex.audit hex.build hex.config hex.docs hex.info hex.organization hex.key hex.outdated hex.owner hex.package hex.publish hex.registry hex.repo hex.retire hex.search hex.sponsor hex.user loadconfig local local.hex local.phoenix local.phx local.public_keys local.rebar nerves.artifact nerves.artifact.get nerves.info nerves.new nerves.release.init new phoenix.digest phoenix.gen.channel phoenix.gen.html phoenix.gen.json phoenix.gen.model phoenix.gen.secret phoenix.new phoenix.routes phoenix.server phx.digest phx.digest.clean phx.gen.auth phx.gen.cert phx.gen.channel phx.gen.context phx.gen.embedded phx.gen.html phx.gen.json phx.gen.live phx.gen.notifier phx.gen.presence phx.gen.schema phx.gen.secret phx.gen.socket phx.new phx.new.ecto phx.new.web phx.routes phx.server profile.cprof profile.eprof profile.fprof release release.init run test test.coverage xref)
_wanted tasks expl 'help' compadd $tasks
}

View file

@ -1,39 +1,46 @@
# Calls ./mvnw if found, otherwise execute the original mvn
# Calls mvnw if found in the current project, otherwise execute the original mvn
mvn-or-mvnw() {
if [ -x ./mvnw ]; then
echo "executing mvnw instead of mvn"
./mvnw "$@"
else
command mvn "$@"
fi
local dir="$PWD"
while [[ ! -x "$dir/mvnw" && "$dir" != / ]]; do
dir="${dir:h}"
done
if [[ -x "$dir/mvnw" ]]; then
echo "Running \`$dir/mvnw\`..." >&2
"$dir/mvnw" "$@"
return $?
fi
command mvn "$@"
}
# Wrapper function for Maven's mvn command. Based on https://gist.github.com/1027800
mvn-color() {
local BOLD=$(echoti bold)
local TEXT_RED=$(echoti setaf 1)
local TEXT_GREEN=$(echoti setaf 2)
local TEXT_YELLOW=$(echoti setaf 3)
local TEXT_BLUE=$(echoti setaf 4)
local TEXT_WHITE=$(echoti setaf 7)
local RESET_FORMATTING=$(echoti sgr0)
(
# Filter mvn output using sed. Before filtering set the locale to C, so invalid characters won't break some sed implementations
unset LANG
LC_CTYPE=C mvn "$@" | sed \
-e "s/\(\[INFO\]\)\(.*\)/${TEXT_BLUE}${BOLD}\1${RESET_FORMATTING}\2/g" \
-e "s/\(\[DEBUG\]\)\(.*\)/${TEXT_WHITE}${BOLD}\1${RESET_FORMATTING}\2/g" \
-e "s/\(\[INFO\]\ BUILD SUCCESSFUL\)/${BOLD}${TEXT_GREEN}\1${RESET_FORMATTING}/g" \
-e "s/\(\[WARNING\]\)\(.*\)/${BOLD}${TEXT_YELLOW}\1${RESET_FORMATTING}\2/g" \
-e "s/\(\[ERROR\]\)\(.*\)/${BOLD}${TEXT_RED}\1${RESET_FORMATTING}\2/g" \
-e "s/Tests run: \([^,]*\), Failures: \([^,]*\), Errors: \([^,]*\), Skipped: \([^,]*\)/${BOLD}${TEXT_GREEN}Tests run: \1${RESET_FORMATTING}, Failures: ${BOLD}${TEXT_RED}\2${RESET_FORMATTING}, Errors: ${BOLD}${TEXT_RED}\3${RESET_FORMATTING}, Skipped: ${BOLD}${TEXT_YELLOW}\4${RESET_FORMATTING}/g"
local BOLD=$(echoti bold)
local TEXT_RED=$(echoti setaf 1)
local TEXT_GREEN=$(echoti setaf 2)
local TEXT_YELLOW=$(echoti setaf 3)
local TEXT_BLUE=$(echoti setaf 4)
local TEXT_WHITE=$(echoti setaf 7)
local RESET_FORMATTING=$(echoti sgr0)
# Make sure formatting is reset
echo -ne "${RESET_FORMATTING}"
)
(
# Filter mvn output using sed. Before filtering set the locale to C, so invalid characters won't break some sed implementations
unset LANG
LC_CTYPE=C mvn "$@" | sed \
-e "s/\(\[INFO\]\)\(.*\)/${TEXT_BLUE}${BOLD}\1${RESET_FORMATTING}\2/g" \
-e "s/\(\[DEBUG\]\)\(.*\)/${TEXT_WHITE}${BOLD}\1${RESET_FORMATTING}\2/g" \
-e "s/\(\[INFO\]\ BUILD SUCCESSFUL\)/${BOLD}${TEXT_GREEN}\1${RESET_FORMATTING}/g" \
-e "s/\(\[WARNING\]\)\(.*\)/${BOLD}${TEXT_YELLOW}\1${RESET_FORMATTING}\2/g" \
-e "s/\(\[ERROR\]\)\(.*\)/${BOLD}${TEXT_RED}\1${RESET_FORMATTING}\2/g" \
-e "s/Tests run: \([^,]*\), Failures: \([^,]*\), Errors: \([^,]*\), Skipped: \([^,]*\)/${BOLD}${TEXT_GREEN}Tests run: \1${RESET_FORMATTING}, Failures: ${BOLD}${TEXT_RED}\2${RESET_FORMATTING}, Errors: ${BOLD}${TEXT_RED}\3${RESET_FORMATTING}, Skipped: ${BOLD}${TEXT_YELLOW}\4${RESET_FORMATTING}/g"
# Make sure formatting is reset
echo -ne "${RESET_FORMATTING}"
)
}
# either use orignal mvn or the mvn wrapper
# either use original mvn or the mvn wrapper
alias mvn="mvn-or-mvnw"
# Run mvn against the pom found in a project's root directory (assumes a git repo)
@ -72,262 +79,262 @@ alias mvn-updates='mvn versions:display-dependency-updates'
function listMavenCompletions {
local file new_file
local -a profiles POM_FILES modules
local file new_file
local -a profiles POM_FILES modules
# Root POM
POM_FILES=(~/.m2/settings.xml)
# Root POM
POM_FILES=(~/.m2/settings.xml)
# POM in the current directory
if [[ -f pom.xml ]]; then
local file=pom.xml
POM_FILES+=("${file:A}")
fi
# POM in the current directory
if [[ -f pom.xml ]]; then
local file=pom.xml
POM_FILES+=("${file:A}")
fi
# Look for POM files in parent directories
while [[ -n "$file" ]] && grep -q "<parent>" "$file"; do
# look for a new relativePath for parent pom.xml
new_file=$(grep -e "<relativePath>.*</relativePath>" "$file" | sed -e 's/.*<relativePath>\(.*\)<\/relativePath>.*/\1/')
# Look for POM files in parent directories
while [[ -n "$file" ]] && grep -q "<parent>" "$file"; do
# look for a new relativePath for parent pom.xml
new_file=$(grep -e "<relativePath>.*</relativePath>" "$file" | sed -e 's/.*<relativePath>\(.*\)<\/relativePath>.*/\1/')
# if <parent> is present but not defined, assume ../pom.xml
if [[ -z "$new_file" ]]; then
new_file="../pom.xml"
fi
# if <parent> is present but not defined, assume ../pom.xml
if [[ -z "$new_file" ]]; then
new_file="../pom.xml"
fi
# if file doesn't exist break
file="${file:h}/${new_file}"
if ! [[ -e "$file" ]]; then
break
fi
# if file doesn't exist break
file="${file:h}/${new_file}"
if ! [[ -e "$file" ]]; then
break
fi
POM_FILES+=("${file:A}")
done
POM_FILES+=("${file:A}")
done
# Get profiles from found files
for file in $POM_FILES; do
[[ -e $file ]] || continue
profiles+=($(sed 's/<!--.*-->//' "$file" | sed '/<!--/,/-->/d' | grep -e "<profile>" -A 1 | grep -e "<id>.*</id>" | sed 's?.*<id>\(.*\)<\/id>.*?-P\1?'))
done
# Get profiles from found files
for file in $POM_FILES; do
[[ -e $file ]] || continue
profiles+=($(sed 's/<!--.*-->//' "$file" | sed '/<!--/,/-->/d' | grep -e "<profile>" -A 1 | grep -e "<id>.*</id>" | sed 's?.*<id>\(.*\)<\/id>.*?-P\1?'))
done
# List modules
modules=($(find **/pom.xml -type f | grep -v '/target/classes/META-INF/' | grep '/pom.xml' |sed 's|\(.*\)/pom\.xml|\1|'))
# List modules
modules=($(find **/pom.xml -type f | grep -v '/target/classes/META-INF/' | grep '/pom.xml' |sed 's|\(.*\)/pom\.xml|\1|'))
reply=(
# common lifecycle
clean initialize process-resources compile process-test-resources test-compile test package verify install deploy site
reply=(
# common lifecycle
clean initialize process-resources compile process-test-resources test-compile test package verify install deploy site
# integration testing
pre-integration-test integration-test
# integration testing
pre-integration-test integration-test
# common plugins
deploy failsafe install site surefire checkstyle javadoc jxr pmd ant antrun archetype assembly dependency enforcer gpg help release repository source eclipse idea jetty cargo jboss tomcat tomcat6 tomcat7 exec versions war ear ejb android scm buildnumber nexus repository sonar license hibernate3 liquibase flyway gwt
# common plugins
deploy failsafe install site surefire checkstyle javadoc jxr pmd ant antrun archetype assembly dependency enforcer gpg help release repository source eclipse idea jetty cargo jboss tomcat tomcat6 tomcat7 exec versions war ear ejb android scm buildnumber nexus repository sonar license hibernate3 liquibase flyway gwt
# deploy
deploy:deploy-file
# failsafe
failsafe:integration-test failsafe:verify
# install
install:install-file install:help
# site
site:site site:deploy site:run site:stage site:stage-deploy site:attach-descriptor site:jar site:effective-site
# surefire
surefire:test
# deploy
deploy:deploy-file
# failsafe
failsafe:integration-test failsafe:verify
# install
install:install-file install:help
# site
site:site site:deploy site:run site:stage site:stage-deploy site:attach-descriptor site:jar site:effective-site
# surefire
surefire:test
# checkstyle
checkstyle:checkstyle checkstyle:check checkstyle:checkstyle-aggregate
# javadoc
javadoc:javadoc javadoc:test-javadoc javadoc:javadoc-no-fork javadoc:test-javadoc-no-fork javadoc:aggregate javadoc:test-aggregate javadoc:jar javadoc:test-jar javadoc:aggregate-jar javadoc:test-aggregate-jar javadoc:fix javadoc:test-fix javadoc:resource-bundle javadoc:test-resource-bundle
# jxr
jxr:jxr jxr:aggregate jxr:test-jxr jxr:test-aggregate
# pmd
pmd:pmd pmd:cpd pmd:check pmd:cpd-check
# checkstyle
checkstyle:checkstyle checkstyle:check checkstyle:checkstyle-aggregate
# javadoc
javadoc:javadoc javadoc:test-javadoc javadoc:javadoc-no-fork javadoc:test-javadoc-no-fork javadoc:aggregate javadoc:test-aggregate javadoc:jar javadoc:test-jar javadoc:aggregate-jar javadoc:test-aggregate-jar javadoc:fix javadoc:test-fix javadoc:resource-bundle javadoc:test-resource-bundle
# jxr
jxr:jxr jxr:aggregate jxr:test-jxr jxr:test-aggregate
# pmd
pmd:pmd pmd:cpd pmd:check pmd:cpd-check
# ant
ant:ant ant:clean
# antrun
antrun:run
# archetype
archetype:generate archetype:create-from-project archetype:crawl
# assembly
assembly:single assembly:assembly
# dependency
dependency:analyze dependency:analyze-dep-mgt dependency:analyze-only dependency:analyze-report dependency:analyze-duplicate dependency:build-classpath dependency:copy dependency:copy-dependencies dependency:display-ancestors dependency:get dependency:go-offline dependency:list dependency:list-repositories dependency:properties dependency:purge-local-repository dependency:resolve dependency:resolve-plugins dependency:sources dependency:tree dependency:unpack dependency:unpack-dependencies
# enforcer
enforcer:enforce enforcer:display-info
# gpg
gpg:sign gpg:sign-and-deploy-file
# help
help:active-profiles help:all-profiles help:describe help:effective-pom help:effective-settings help:evaluate help:expressions help:system
# release
release:clean release:prepare release:prepare-with-pom release:rollback release:perform release:stage release:branch release:update-versions
# jgitflow
jgitflow:feature-start jgitflow:feature-finish jgitflow:release-start jgitflow:release-finish jgitflow:hotfix-start jgitflow:hotfix-finish jgitflow:build-number
# repository
repository:bundle-create repository:bundle-pack
# source
source:aggregate source:jar source:jar-no-fork source:test-jar source:test-jar-no-fork
# ant
ant:ant ant:clean
# antrun
antrun:run
# archetype
archetype:generate archetype:create-from-project archetype:crawl
# assembly
assembly:single assembly:assembly
# dependency
dependency:analyze dependency:analyze-dep-mgt dependency:analyze-only dependency:analyze-report dependency:analyze-duplicate dependency:build-classpath dependency:copy dependency:copy-dependencies dependency:display-ancestors dependency:get dependency:go-offline dependency:list dependency:list-repositories dependency:properties dependency:purge-local-repository dependency:resolve dependency:resolve-plugins dependency:sources dependency:tree dependency:unpack dependency:unpack-dependencies
# enforcer
enforcer:enforce enforcer:display-info
# gpg
gpg:sign gpg:sign-and-deploy-file
# help
help:active-profiles help:all-profiles help:describe help:effective-pom help:effective-settings help:evaluate help:expressions help:system
# release
release:clean release:prepare release:prepare-with-pom release:rollback release:perform release:stage release:branch release:update-versions
# jgitflow
jgitflow:feature-start jgitflow:feature-finish jgitflow:release-start jgitflow:release-finish jgitflow:hotfix-start jgitflow:hotfix-finish jgitflow:build-number
# repository
repository:bundle-create repository:bundle-pack
# source
source:aggregate source:jar source:jar-no-fork source:test-jar source:test-jar-no-fork
# eclipse
eclipse:clean eclipse:eclipse
# idea
idea:clean idea:idea
# eclipse
eclipse:clean eclipse:eclipse
# idea
idea:clean idea:idea
# jetty
jetty:run jetty:run-exploded
# cargo
cargo:start cargo:run cargo:stop cargo:deploy cargo:undeploy cargo:help
# jboss
jboss:start jboss:stop jboss:deploy jboss:undeploy jboss:redeploy
# tomcat
tomcat:start tomcat:stop tomcat:deploy tomcat:undeploy tomcat:redeploy
# tomcat6
tomcat6:run tomcat6:run-war tomcat6:run-war-only tomcat6:stop tomcat6:deploy tomcat6:undeploy
# tomcat7
tomcat7:run tomcat7:run-war tomcat7:run-war-only tomcat7:deploy
# tomee
tomee:run tomee:run-war tomee:run-war-only tomee:stop tomee:deploy tomee:undeploy
# spring-boot
spring-boot:run spring-boot:repackage
# quarkus
quarkus:dev quarkus:list-extensions quarkus:add-extension quarkus:add-extensions quarkus:generate-config quarkus:help
# exec
exec:exec exec:java
# versions
versions:display-dependency-updates versions:display-plugin-updates versions:display-property-updates versions:update-parent versions:update-properties versions:update-child-modules versions:lock-snapshots versions:unlock-snapshots versions:resolve-ranges versions:set versions:use-releases versions:use-next-releases versions:use-latest-releases versions:use-next-snapshots versions:use-latest-snapshots versions:use-next-versions versions:use-latest-versions versions:commit versions:revert
# scm
scm:add scm:bootstrap scm:branch scm:changelog scm:check-local-modification scm:checkin scm:checkout scm:diff scm:edit scm:export scm:list scm:remove scm:status scm:tag scm:unedit scm:update scm:update-subprojects scm:validate
# buildnumber
buildnumber:create buildnumber:create-timestamp buildnumber:help buildnumber:hgchangeset
# jetty
jetty:run jetty:run-exploded
# cargo
cargo:start cargo:run cargo:stop cargo:deploy cargo:undeploy cargo:help
# jboss
jboss:start jboss:stop jboss:deploy jboss:undeploy jboss:redeploy
# tomcat
tomcat:start tomcat:stop tomcat:deploy tomcat:undeploy tomcat:redeploy
# tomcat6
tomcat6:run tomcat6:run-war tomcat6:run-war-only tomcat6:stop tomcat6:deploy tomcat6:undeploy
# tomcat7
tomcat7:run tomcat7:run-war tomcat7:run-war-only tomcat7:deploy
# tomee
tomee:run tomee:run-war tomee:run-war-only tomee:stop tomee:deploy tomee:undeploy
# spring-boot
spring-boot:run spring-boot:repackage
# quarkus
quarkus:dev quarkus:list-extensions quarkus:add-extension quarkus:add-extensions quarkus:generate-config quarkus:help
# exec
exec:exec exec:java
# versions
versions:display-dependency-updates versions:display-plugin-updates versions:display-property-updates versions:update-parent versions:update-properties versions:update-child-modules versions:lock-snapshots versions:unlock-snapshots versions:resolve-ranges versions:set versions:use-releases versions:use-next-releases versions:use-latest-releases versions:use-next-snapshots versions:use-latest-snapshots versions:use-next-versions versions:use-latest-versions versions:commit versions:revert
# scm
scm:add scm:bootstrap scm:branch scm:changelog scm:check-local-modification scm:checkin scm:checkout scm:diff scm:edit scm:export scm:list scm:remove scm:status scm:tag scm:unedit scm:update scm:update-subprojects scm:validate
# buildnumber
buildnumber:create buildnumber:create-timestamp buildnumber:help buildnumber:hgchangeset
# war
war:war war:exploded war:inplace war:manifest
# ear
ear:ear ear:generate-application-xml
# ejb
ejb:ejb
# android
android:apk android:apklib android:deploy android:deploy-dependencies android:dex android:emulator-start android:emulator-stop android:emulator-stop-all android:generate-sources android:help android:instrument android:manifest-update android:pull android:push android:redeploy android:run android:undeploy android:unpack android:version-update android:zipalign android:devices
# nexus
nexus:staging-list nexus:staging-close nexus:staging-drop nexus:staging-release nexus:staging-build-promotion nexus:staging-profiles-list nexus:settings-download
# repository
repository:bundle-create repository:bundle-pack repository:help
# war
war:war war:exploded war:inplace war:manifest
# ear
ear:ear ear:generate-application-xml
# ejb
ejb:ejb
# android
android:apk android:apklib android:deploy android:deploy-dependencies android:dex android:emulator-start android:emulator-stop android:emulator-stop-all android:generate-sources android:help android:instrument android:manifest-update android:pull android:push android:redeploy android:run android:undeploy android:unpack android:version-update android:zipalign android:devices
# nexus
nexus:staging-list nexus:staging-close nexus:staging-drop nexus:staging-release nexus:staging-build-promotion nexus:staging-profiles-list nexus:settings-download
# repository
repository:bundle-create repository:bundle-pack repository:help
# sonar
sonar:sonar
# license
license:format license:check
# hibernate3
hibernate3:hbm2ddl hibernate3:help
# liquibase
liquibase:changelogSync liquibase:changelogSyncSQL liquibase:clearCheckSums liquibase:dbDoc liquibase:diff liquibase:dropAll liquibase:help liquibase:migrate liquibase:listLocks liquibase:migrateSQL liquibase:releaseLocks liquibase:rollback liquibase:rollbackSQL liquibase:status liquibase:tag liquibase:update liquibase:updateSQL liquibase:updateTestingRollback
# flyway
flyway:clean flyway:history flyway:init flyway:migrate flyway:status flyway:validate
# gwt
gwt:browser gwt:clean gwt:compile gwt:compile-report gwt:css gwt:debug gwt:eclipse gwt:eclipseTest gwt:generateAsync gwt:help gwt:i18n gwt:mergewebxml gwt:resources gwt:run gwt:sdkInstall gwt:source-jar gwt:soyc gwt:test
# asciidoctor
asciidoctor:process-asciidoc asciidoctor:auto-refresh asciidoctor:http asciidoctor:zip
# compiler
compiler:compile compiler:testCompile
# resources
resources:resources resources:testResources resources:copy-resources
# verifier
verifier:verify
# jar
jar:jar jar:test-jar
# rar
rar:rar
# acr
acr:acr
# shade
shade:shade
# changelog
changelog:changelog changelog:dev-activity changelog:file-activity
# changes
changes:announcement-mail changes:announcement-generate changes:changes-check changes:changes-validate changes:changes-report changes:jira-report changes:trac-report changes:github-report
# doap
doap:generate
# docck
docck:check
# jdeps
jdeps:jdkinternals jdeps:test-jdkinternals
# linkcheck
linkcheck:linkcheck
# project-info-reports
project-info-reports:cim project-info-reports:dependencies project-info-reports:dependency-convergence project-info-reports:dependency-info project-info-reports:dependency-management project-info-reports:distribution-management project-info-reports:help project-info-reports:index project-info-reports:issue-tracking project-info-reports:license project-info-reports:mailing-list project-info-reports:modules project-info-reports:plugin-management project-info-reports:plugins project-info-reports:project-team project-info-reports:scm project-info-reports:summary
# surefire-report
surefire-report:failsafe-report-only surefire-report:report surefire-report:report-only
# invoker
invoker:install invoker:integration-test invoker:verify invoker:run
# jarsigner
jarsigner:sign jarsigner:verify
# patch
patch:apply
# pdf
pdf:pdf
# plugin
plugin:descriptor plugin:report plugin:updateRegistry plugin:addPluginArtifactMetadata plugin:helpmojo
# remote-resources
remote-resources:bundle remote-resources:process
# scm-publish
scm-publish:help scm-publish:publish-scm scm-publish:scmpublish
# stage
stage:copy
# toolchain
toolchain:toolchain
#liberty
liberty:clean-server liberty:compile-jsp liberty:configure-arquillian liberty:create-server liberty:debug liberty:debug-server liberty:deploy liberty:dev liberty:display-url liberty:dump-server liberty:install-apps liberty:install-feature liberty:install-server liberty:java-dump-server liberty:package-server liberty:run liberty:run-server liberty:server-status liberty:start liberty:start-server liberty:status liberty:stop liberty:stop-server liberty:test-start-server liberty:test-stop-server liberty:undeploy liberty:uninstall-feature
# sonar
sonar:sonar
# license
license:format license:check
# hibernate3
hibernate3:hbm2ddl hibernate3:help
# liquibase
liquibase:changelogSync liquibase:changelogSyncSQL liquibase:clearCheckSums liquibase:dbDoc liquibase:diff liquibase:dropAll liquibase:help liquibase:migrate liquibase:listLocks liquibase:migrateSQL liquibase:releaseLocks liquibase:rollback liquibase:rollbackSQL liquibase:status liquibase:tag liquibase:update liquibase:updateSQL liquibase:updateTestingRollback
# flyway
flyway:clean flyway:history flyway:init flyway:migrate flyway:status flyway:validate
# gwt
gwt:browser gwt:clean gwt:compile gwt:compile-report gwt:css gwt:debug gwt:eclipse gwt:eclipseTest gwt:generateAsync gwt:help gwt:i18n gwt:mergewebxml gwt:resources gwt:run gwt:sdkInstall gwt:source-jar gwt:soyc gwt:test
# asciidoctor
asciidoctor:process-asciidoc asciidoctor:auto-refresh asciidoctor:http asciidoctor:zip
# compiler
compiler:compile compiler:testCompile
# resources
resources:resources resources:testResources resources:copy-resources
# verifier
verifier:verify
# jar
jar:jar jar:test-jar
# rar
rar:rar
# acr
acr:acr
# shade
shade:shade
# changelog
changelog:changelog changelog:dev-activity changelog:file-activity
# changes
changes:announcement-mail changes:announcement-generate changes:changes-check changes:changes-validate changes:changes-report changes:jira-report changes:trac-report changes:github-report
# doap
doap:generate
# docck
docck:check
# jdeps
jdeps:jdkinternals jdeps:test-jdkinternals
# linkcheck
linkcheck:linkcheck
# project-info-reports
project-info-reports:cim project-info-reports:dependencies project-info-reports:dependency-convergence project-info-reports:dependency-info project-info-reports:dependency-management project-info-reports:distribution-management project-info-reports:help project-info-reports:index project-info-reports:issue-tracking project-info-reports:license project-info-reports:mailing-list project-info-reports:modules project-info-reports:plugin-management project-info-reports:plugins project-info-reports:project-team project-info-reports:scm project-info-reports:summary
# surefire-report
surefire-report:failsafe-report-only surefire-report:report surefire-report:report-only
# invoker
invoker:install invoker:integration-test invoker:verify invoker:run
# jarsigner
jarsigner:sign jarsigner:verify
# patch
patch:apply
# pdf
pdf:pdf
# plugin
plugin:descriptor plugin:report plugin:updateRegistry plugin:addPluginArtifactMetadata plugin:helpmojo
# remote-resources
remote-resources:bundle remote-resources:process
# scm-publish
scm-publish:help scm-publish:publish-scm scm-publish:scmpublish
# stage
stage:copy
# toolchain
toolchain:toolchain
#liberty
liberty:clean-server liberty:compile-jsp liberty:configure-arquillian liberty:create-server liberty:debug liberty:debug-server liberty:deploy liberty:dev liberty:display-url liberty:dump-server liberty:install-apps liberty:install-feature liberty:install-server liberty:java-dump-server liberty:package-server liberty:run liberty:run-server liberty:server-status liberty:start liberty:start-server liberty:status liberty:stop liberty:stop-server liberty:test-start-server liberty:test-stop-server liberty:undeploy liberty:uninstall-feature
# options
"-Dmaven.test.skip=true" -DskipTests -DskipITs -Dmaven.surefire.debug -DenableCiProfile "-Dpmd.skip=true" "-Dcheckstyle.skip=true" "-Dtycho.mode=maven" "-Dmaven.test.failure.ignore=true" "-DgroupId=" "-DartifactId=" "-Dversion=" "-Dpackaging=jar" "-Dfile="
# options
"-Dmaven.test.skip=true" -DskipTests -DskipITs -Dmaven.surefire.debug -DenableCiProfile "-Dpmd.skip=true" "-Dcheckstyle.skip=true" "-Dtycho.mode=maven" "-Dmaven.test.failure.ignore=true" "-DgroupId=" "-DartifactId=" "-Dversion=" "-Dpackaging=jar" "-Dfile="
# arguments
-am --also-make
-amd --also-make-dependents-am
-B --batch-mode
-b --builder
-C --strict-checksums
-c --lax-checksums
-cpu --check-plugin-updates
-D --define
-e --errors
-emp --encrypt-master-password
-ep --encrypt-password
-f --file
-fae --fail-at-end
-ff --fail-fast
-fn --fail-never
-gs --global-settings
-gt --global-toolchains
-h --help
-l --log-file
-llr --legacy-local-repository
-N --non-recursive
-npr --no-plugin-registry
-npu --no-plugin-updates
-nsu --no-snapshot-updates
-o --offline
-P --activate-profiles
-pl --projects
-q --quiet
-rf --resume-from
-s --settings
-t --toolchains
-T --threads
-U --update-snapshots
-up --update-plugins
-v --version
-V --show-version
-X --debug
# arguments
-am --also-make
-amd --also-make-dependents-am
-B --batch-mode
-b --builder
-C --strict-checksums
-c --lax-checksums
-cpu --check-plugin-updates
-D --define
-e --errors
-emp --encrypt-master-password
-ep --encrypt-password
-f --file
-fae --fail-at-end
-ff --fail-fast
-fn --fail-never
-gs --global-settings
-gt --global-toolchains
-h --help
-l --log-file
-llr --legacy-local-repository
-N --non-recursive
-npr --no-plugin-registry
-npu --no-plugin-updates
-nsu --no-snapshot-updates
-o --offline
-P --activate-profiles
-pl --projects
-q --quiet
-rf --resume-from
-s --settings
-t --toolchains
-T --threads
-U --update-snapshots
-up --update-plugins
-v --version
-V --show-version
-X --debug
cli:execute cli:execute-phase
archetype:generate generate-sources
cobertura:cobertura
-Dtest=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dtest=\1?' ; fi)
-Dit.test=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dit.test=\1?' ; fi)
cli:execute cli:execute-phase
archetype:generate generate-sources
cobertura:cobertura
-Dtest=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dtest=\1?' ; fi)
-Dit.test=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dit.test=\1?' ; fi)
$profiles
$modules
)
$profiles
$modules
)
}
compctl -K listMavenCompletions mvn mvnw

1
plugins/osx Symbolic link
View file

@ -0,0 +1 @@
macos

View file

@ -1,62 +0,0 @@
# OSX plugin
This plugin provides a few utilities to make it more enjoyable on macOS (previously named OSX).
To start using it, add the `osx` plugin to your plugins array in `~/.zshrc`:
```zsh
plugins=(... osx)
```
Original author: [Sorin Ionescu](https://github.com/sorin-ionescu)
## Commands
| Command | Description |
| :-------------- | :---------------------------------------------------- |
| `tab` | Open the current directory in a new tab |
| `split_tab` | Split the current terminal tab horizontally |
| `vsplit_tab` | Split the current terminal tab vertically |
| `ofd` | Open the current directory in a Finder window |
| `pfd` | Return the path of the frontmost Finder window |
| `pfs` | Return the current Finder selection |
| `cdf` | `cd` to the current Finder directory |
| `pushdf` | `pushd` to the current Finder directory |
| `pxd` | Return the current Xcode project directory |
| `cdx` | `cd` to the current Xcode project directory |
| `quick-look` | Quick-Look a specified file |
| `man-preview` | Open a specified man page in Preview app |
| `showfiles` | Show hidden files in Finder |
| `hidefiles` | Hide the hidden files in Finder |
| `itunes` | _DEPRECATED_. Use `music` from macOS Catalina on |
| `music` | Control Apple Music. Use `music -h` for usage details |
| `spotify` | Control Spotify and search by artist, album, track… |
| `rmdsstore` | Remove .DS\_Store files recursively in a directory |
| `btrestart` | Restart the Bluetooth daemon |
## Acknowledgements
This application makes use of the following third party scripts:
[shpotify](https://github.com/hnarayanan/shpotify)
Copyright (c) 20122019 [Harish Narayanan](https://harishnarayanan.org/).
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -32,7 +32,7 @@
#
# Copyright (c) 2014 Jim Hester
#
# This software is provided 'as-is', without any express or implied warranty.
# This software is provided 'as-is', without any express or implied warranty.
# In no event will the authors be held liable for any damages arising from the
# use of this software.
#
@ -57,6 +57,7 @@
#-------------------------------------------------------------------------------
[[ -z $HISTORY_BASE ]] && HISTORY_BASE="$HOME/.directory_history"
[[ -z $HISTORY_START_WITH_GLOBAL ]] && HISTORY_START_WITH_GLOBAL=false
[[ -z $PER_DIRECTORY_HISTORY_TOGGLE ]] && PER_DIRECTORY_HISTORY_TOGGLE='^G'
#-------------------------------------------------------------------------------
@ -66,9 +67,11 @@
function per-directory-history-toggle-history() {
if [[ $_per_directory_history_is_global == true ]]; then
_per-directory-history-set-directory-history
_per_directory_history_is_global=false
print -n "\nusing local history"
else
_per-directory-history-set-global-history
_per_directory_history_is_global=true
print -n "\nusing global history"
fi
zle .push-line
@ -114,43 +117,58 @@ function _per-directory-history-addhistory() {
true
else
print -Sr -- "${1%%$'\n'}"
# instantly write history if set options require it.
if [[ -o share_history ]] || \
[[ -o inc_append_history ]] || \
[[ -o inc_append_history_time ]]; then
fc -AI $HISTFILE
fc -AI $_per_directory_history_directory
fi
fc -p $_per_directory_history_directory
fi
}
function _per-directory-history-precmd() {
if [[ $_per_directory_history_initialized == false ]]; then
_per_directory_history_initialized=true
if [[ $HISTORY_START_WITH_GLOBAL == true ]]; then
_per-directory-history-set-global-history
_per_directory_history_is_global=true
else
_per-directory-history-set-directory-history
_per_directory_history_is_global=false
fi
fi
}
function _per-directory-history-set-directory-history() {
if [[ $_per_directory_history_is_global == true ]]; then
fc -AI $HISTFILE
local original_histsize=$HISTSIZE
HISTSIZE=0
HISTSIZE=$original_histsize
if [[ -e "$_per_directory_history_directory" ]]; then
fc -R "$_per_directory_history_directory"
fi
fc -AI $HISTFILE
local original_histsize=$HISTSIZE
HISTSIZE=0
HISTSIZE=$original_histsize
if [[ -e "$_per_directory_history_directory" ]]; then
fc -R "$_per_directory_history_directory"
fi
_per_directory_history_is_global=false
}
function _per-directory-history-set-global-history() {
if [[ $_per_directory_history_is_global == false ]]; then
fc -AI $_per_directory_history_directory
local original_histsize=$HISTSIZE
HISTSIZE=0
HISTSIZE=$original_histsize
if [[ -e "$HISTFILE" ]]; then
fc -R "$HISTFILE"
fi
fi
_per_directory_history_is_global=true
}
function _per-directory-history-set-global-history() {
fc -AI $_per_directory_history_directory
local original_histsize=$HISTSIZE
HISTSIZE=0
HISTSIZE=$original_histsize
if [[ -e "$HISTFILE" ]]; then
fc -R "$HISTFILE"
fi
}
mkdir -p ${_per_directory_history_directory:h}
#add functions to the exec list for chpwd and zshaddhistory
autoload -U add-zsh-hook
add-zsh-hook chpwd _per-directory-history-change-directory
add-zsh-hook zshaddhistory _per-directory-history-addhistory
add-zsh-hook precmd _per-directory-history-precmd
#start in directory mode
mkdir -p ${_per_directory_history_directory:h}
_per_directory_history_is_global=true
_per-directory-history-set-directory-history
# set initialized flag to false
_per_directory_history_initialized=false

View file

@ -1,20 +1,23 @@
## percol
# percol
Provides some useful function to make [percol](https://github.com/mooz/percol) work with zsh history and [jump plugin](https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/jump/jump.plugin.zsh)
Provides some useful function to make [percol](https://github.com/mooz/percol) work with zsh history and
the [jump plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/jump), optionally.
### Requirements
To use it, add `percol` to the plugins array in your zshrc:
```shell
pip install percol
```zsh
plugins=(... percol)
```
And [jump](https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/jump/jump.plugin.zsh) for `oh-my-zsh` is a optional requirement.
## Requirements
### Usage
- `percol`: install with `pip install percol`.
For default
- (_Optional_) [`jump`](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/jump) plugin: needs to be
enabled before the `percol` plugin.
- `^-r` bind to `percol_select_history`.You can use it to grep your history with percol.
## Usage
- `^-b` bind to `percol_select_marks`.You can use it to grep your bookmarks with percol.
- <kbd>CTRL-R</kbd> (bound to `percol_select_history`): you can use it to grep your history with percol.
- <kbd>CTRL-B</kbd> (bound to `percol_select_marks`): you can use it to grep your jump bookmarks with percol.

View file

@ -1,22 +1,25 @@
if which percol &> /dev/null; then
function percol_select_history() {
local tac
which gtac &> /dev/null && tac="gtac" || { which tac &> /dev/null && tac="tac" || { tac="tail -r" } }
BUFFER=$(fc -l -n 1 | eval $tac | percol --query "$LBUFFER")
CURSOR=$#BUFFER
zle -R -c
}
(( ${+commands[percol]} )) || return
zle -N percol_select_history
bindkey '^R' percol_select_history
function percol_select_history() {
# print history in reverse order (from -1 (latest) to 1 (oldest))
BUFFER=$(fc -l -n -1 1 | percol --query "$LBUFFER")
CURSOR=$#BUFFER
zle -R -c
}
zle -N percol_select_history
bindkey -M emacs '^R' percol_select_history
bindkey -M viins '^R' percol_select_history
bindkey -M vicmd '^R' percol_select_history
if which marks &> /dev/null; then
function percol_select_marks() {
BUFFER=$(marks | percol --query "$LBUFFER" | awk '{print $3}')
CURSOR=$#BUFFER # move cursor
zle -R -c # refresh
}
zle -N percol_select_marks
bindkey '^B' percol_select_marks
fi
if (( ${+functions[marks]} )); then
function percol_select_marks() {
# parse directory from marks output (markname -> path) and quote if necessary
BUFFER=${(q)"$(marks | percol --query "$LBUFFER")"##*-> }
CURSOR=$#BUFFER
zle -R -c
}
zle -N percol_select_marks
bindkey -M emacs '^B' percol_select_marks
bindkey -M viins '^B' percol_select_marks
bindkey -M vicmd '^B' percol_select_marks
fi

View file

@ -78,7 +78,7 @@ if [[ $FOUND_PYENV -eq 1 ]]; then
eval "$(pyenv init - --no-rehash zsh)"
# If pyenv-virtualenv exists, load it
if [[ -d "$(pyenv root)/plugins/pyenv-virtualenv" && "$ZSH_PYENV_VIRTUALENV" != false ]]; then
if [[ "$(pyenv commands)" =~ "virtualenv-init" && "$ZSH_PYENV_VIRTUALENV" != false ]]; then
eval "$(pyenv virtualenv-init - zsh)"
fi

View file

@ -11,6 +11,7 @@ plugins=(... python)
| Command | Description |
|------------------|---------------------------------------------------------------------------------|
| `py` | Runs `python` |
| `ipython` | Runs the appropriate `ipython` version according to the activated virtualenv |
| `pyfind` | Finds .py files recursively in the current directory |
| `pyclean [dirs]` | Deletes byte-code and cache files from a list of directories or the current one |

View file

@ -1,14 +1,23 @@
if ! (( $+commands[curl] )); then
echo "rand-quote plugin needs curl to work" >&2
return
echo "rand-quote plugin needs curl to work" >&2
return
fi
function quote {
emulate -L zsh
Q=$(curl -s --connect-timeout 2 "http://www.quotationspage.com/random.php" | iconv -c -f ISO-8859-1 -t UTF-8 | grep -m 1 "dt ")
setopt localoptions nopromptsubst
TXT=$(echo "$Q" | sed -e 's/<\/dt>.*//g' -e 's/.*html//g' -e 's/^[^a-zA-Z]*//' -e 's/<\/a..*$//g')
WHO=$(echo "$Q" | sed -e 's/.*\/quotes\///g' -e 's/<.*//g' -e 's/.*">//g')
# Get random quote data
local data
data="$(command curl -s --connect-timeout 2 "http://www.quotationspage.com/random.php" \
| iconv -c -f ISO-8859-1 -t UTF-8 \
| command grep -a -m 1 'dt class="quote"')"
[[ -n "$WHO" && -n "$TXT" ]] && print -P "%F{3}${WHO}%f: “%F{5}${TXT}%f”"
# Exit if could not fetch random quote
[[ -n "$data" ]] || return 0
local quote author
quote=$(sed -e 's|</dt>.*||g' -e 's|.*html||g' -e 's|^[^a-zA-Z]*||' -e 's|</a..*$||g' <<< "$data")
author=$(sed -e 's|.*/quotes/||g' -e 's|<.*||g' -e 's|.*">||g' <<< "$data")
print -P "%F{3}${author}%f: “%F{5}${quote}%f”"
}

View file

@ -10,11 +10,22 @@ plugins=(... ruby)
## Aliases
| Alias | Command | Description |
|-------|----------------------------------------|------------------------------------------------------|
| rb | `ruby` | The Ruby command |
| sgem | `sudo gem` | Run sudo gem on the system ruby, not the active ruby |
| rfind | `find . -name "*.rb" \| xargs grep -n` | Find ruby file |
| gin | `gem install` | Install a gem into the local repository |
| gun | `gem uninstall` | Uninstall gems from the local repository |
| gli | `gem list` | Display gems installed locally |
| Alias | Command | Description |
|--------|----------------------------------------|------------------------------------------------------|
| rb | `ruby` | The Ruby command |
| sgem | `sudo gem` | Run sudo gem on the system ruby, not the active ruby |
| rfind | `find . -name "*.rb" \| xargs grep -n` | Find ruby file |
| gein | `gem install` | Install a gem into the local repository |
| geun | `gem uninstall` | Uninstall gems from the local repository |
| geli | `gem list` | Display gems installed locally |
| gei | `gem info` | Show information for the given gem |
| geiall | `gem info --all` | Display all gem versions |
| geca | `gem cert --add` | Add a trusted certificate |
| gecr | `gem cert --remove` | Remove a trusted certificate |
| gecb | `gem cert --build` | Build private key and self-signed certificate |
| geclup | `gem cleanup -n` | Do not uninstall gem |
| gegi | `gem generate_index` | Generate index file for gem server |
| geh | `gem help` | Provide additional help |
| gel | `gem lock` | Generate a lockdown list of gems |
| geo | `gem open` | Open gem source in default editor |
| geoe | `gem open -e` | Open gem sources in preferred editor |

View file

@ -1,5 +1,4 @@
# TODO: Make this compatible with rvm.
# Run sudo gem on the system ruby, not the active ruby.
# Run sudo gem on the system ruby, not the active ruby
alias sgem='sudo gem'
# Find ruby file
@ -9,6 +8,17 @@ alias rfind='find . -name "*.rb" | xargs grep -n'
alias rb="ruby"
# Gem Command Shorthands
alias gin="gem install"
alias gun="gem uninstall"
alias gli="gem list"
alias gein="gem install"
alias geun="gem uninstall"
alias geli="gem list"
alias gei="gem info"
alias geiall="gem info --all"
alias geca="gem cert --add"
alias gecr="gem cert --remove"
alias gecb="gem cert --build"
alias geclup="gem cleanup -n"
alias gegi="gem generate_index"
alias geh="gem help"
alias gel="gem lock"
alias geo="gem open"
alias geoe="gem open -e"

View file

@ -270,7 +270,7 @@ fi
# Determine the last recorded directory
if [[ -s ${SCD_HISTFILE} ]]; then
last_directory=${"$(tail -1 ${SCD_HISTFILE})"#*;}
last_directory=${"$(tail -n 1 ${SCD_HISTFILE})"#*;}
fi
# The "record" function adds its arguments to the directory index.

View file

@ -21,7 +21,23 @@ zstyle :omz:plugins:ssh-agent agent-forwarding on
----
To **load multiple identities** use the `identities` style, For example:
To **NOT load any identities on start** use the `lazy` setting. This is particularly
useful when combined with the `AddKeysToAgent` setting (available since OpenSSH 7.2),
since it allows to enter the password only on first use. _NOTE: you can know your
OpenSSH version with `ssh -V`._
```zsh
zstyle :omz:plugins:ssh-agent lazy yes
```
You can enable `AddKeysToAgent` by passing `-o AddKeysToAgent=yes` to the `ssh` command,
or by adding `AddKeysToAgent yes` to your `~/.ssh/config` file [1].
See the [OpenSSH 7.2 Release Notes](http://www.openssh.com/txt/release-7.2).
----
To **load multiple identities** use the `identities` style (**this has no effect
if the `lazy` setting is enabled**). For example:
```zsh
zstyle :omz:plugins:ssh-agent identities id_rsa id_rsa2 id_github

View file

@ -6,9 +6,11 @@ function _start_agent() {
if [[ -f "$ssh_env_cache" ]]; then
. "$ssh_env_cache" > /dev/null
{
[[ "$USERNAME" = root ]] && command ps ax || command ps x
} | command grep ssh-agent | command grep -q $SSH_AGENT_PID && return 0
# Test if $SSH_AUTH_SOCK is visible
zmodload zsh/net/socket
if [[ -S "$SSH_AUTH_SOCK" ]] && zsocket "$SSH_AUTH_SOCK" 2>/dev/null; then
return 0
fi
fi
# Set a maximum lifetime for identities added to ssh-agent
@ -96,7 +98,10 @@ else
_start_agent
fi
_add_identities
# Don't add identities if lazy-loading is enabled
if ! zstyle -t :omz:plugins:ssh-agent lazy; then
_add_identities
fi
unset agent_forwarding ssh_env_cache
unfunction _start_agent _add_identities

View file

@ -17,6 +17,7 @@ alias stn=create_project
if [[ "$OSTYPE" == linux* ]]; then
if [[ "$(uname -r)" = *icrosoft* ]]; then
_sublime_paths=(
"$(wslpath -u 'C:\Program Files\Sublime Text\sublime_text.exe' 2>/dev/null)"
"$(wslpath -u 'C:\Program Files\Sublime Text 3\subl.exe' 2>/dev/null)"
"$(wslpath -u 'C:\Program Files\Sublime Text 2\subl.exe' 2>/dev/null)"
)
@ -52,6 +53,7 @@ alias stn=create_project
)
elif [[ "$OSTYPE" = msys ]]; then
_sublime_paths=(
"/c/Program Files/Sublime Text/sublime_text.exe"
"/c/Program Files/Sublime Text 2/subl.exe"
"/c/Program Files/Sublime Text 3/subl.exe"
)

View file

@ -17,9 +17,9 @@ plugins=(... systemadmin)
| path | `print -l $path` | Displays PATH with each entry on a separate line |
| mkdir | `mkdir -pv` | Automatically create parent directories and display verbose output |
| psmem | `ps -e -orss=,args= \| sort -b -k1 -nr` | Display the processes using the most memory |
| psmem10 | `ps -e -orss=,args= \| sort -b -k1 -nr \| head -10` | Display the top 10 processes using the most memory |
| psmem10 | `ps -e -orss=,args= \| sort -b -k1 -nr \| head -n 10` | Display the top 10 processes using the most memory |
| pscpu | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr` | Display the top processes using the most CPU |
| pscpu10 | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr \| head -10` | Display the top 10 processes using the most CPU |
| pscpu10 | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr \| head -n 10` | Display the top 10 processes using the most CPU |
| hist10 | `print -l ${(o)history%% *} \| uniq -c \| sort -nr \| head -n 10` | Display the top 10 most used commands in the history |
## Functions

View file

@ -26,10 +26,10 @@ alias path='print -l $path'
alias mkdir='mkdir -pv'
# get top process eating memory
alias psmem='ps -e -orss=,args= | sort -b -k1 -nr'
alias psmem10='ps -e -orss=,args= | sort -b -k1 -nr | head -10'
alias psmem10='ps -e -orss=,args= | sort -b -k1 -nr | head -n 10'
# get top process eating cpu if not work try excute : export LC_ALL='C'
alias pscpu='ps -e -o pcpu,cpu,nice,state,cputime,args|sort -k1,1n -nr'
alias pscpu10='ps -e -o pcpu,cpu,nice,state,cputime,args|sort -k1,1n -nr | head -10'
alias pscpu10='ps -e -o pcpu,cpu,nice,state,cputime,args|sort -k1,1n -nr | head -n 10'
# top10 of the history
alias hist10='print -l ${(o)history%% *} | uniq -c | sort -nr | head -n 10'
@ -74,7 +74,7 @@ req20() {
# top20 of Using tcpdump port 80 access to view
http20() {
sudo tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -20
sudo tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -n 20
}
# top20 of Find time_wait connection
@ -99,14 +99,14 @@ accessip10() {
# top20 of Most Visited file or page
visitpage20() {
awk '{print $11}' "$(retlog)"|sort|uniq -c|sort -nr|head -20
awk '{print $11}' "$(retlog)"|sort|uniq -c|sort -nr|head -n 20
}
# top100 of Page lists the most time-consuming (more than 60 seconds) as well as the corresponding page number of occurrences
consume100() {
awk '($NF > 60 && $7~/\.php/){print $7}' "$(retlog)" |sort -n|uniq -c|sort -nr|head -100
awk '($NF > 60 && $7~/\.php/){print $7}' "$(retlog)" |sort -n|uniq -c|sort -nr|head -n 100
# if django website or other webiste make by no suffix language
# awk '{print $7}' "$(retlog)" |sort -n|uniq -c|sort -nr|head -100
# awk '{print $7}' "$(retlog)" |sort -n|uniq -c|sort -nr|head -n 100
}
# Website traffic statistics (G)

View file

@ -39,3 +39,4 @@ The plugin also supports the following:
| `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_UNICODE` | Set `tmux -u` option to support unicode |
| `ZSH_TMUX_DEFAULT_SESSION_NAME` | Set tmux default session name when autostart is enabled |

View file

@ -76,7 +76,11 @@ function _zsh_tmux_plugin_run() {
elif [[ -e "$ZSH_TMUX_CONFIG" ]]; then
tmux_cmd+=(-f "$ZSH_TMUX_CONFIG")
fi
$tmux_cmd new-session
if [[ -n "$ZSH_TMUX_DEFAULT_SESSION_NAME" ]]; then
$tmux_cmd new-session -s $ZSH_TMUX_DEFAULT_SESSION_NAME
else
$tmux_cmd new-session
fi
fi
if [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]]; then

View file

@ -26,7 +26,7 @@ plugins=(... xcode)
### `xc`
Opens the current directory in Xcode as an Xcode project. This will open one of the `.xcworkspace` and `.xcodeproj` files that it can find in the current working directory. You can also specify a directory to look in for the Xcode files.
Opens the current directory in Xcode as an Xcode project or a Swift package. This will open one of the `.xcworkspace`, `.xcodeproj` and `Package.swift` files that it can find in the current working directory. You can also specify a directory to look in for the Xcode files.
Returns 1 if it didn't find any relevant files.
### `xx`

View file

@ -6,28 +6,18 @@ alias xcsel='sudo xcode-select --switch'
# original author: @subdigital
# source: https://gist.github.com/subdigital/5420709
function xc {
local xcode_proj
if [[ $# == 0 ]]; then
xcode_proj=(*.{xcworkspace,xcodeproj}(N))
else
xcode_proj=($1/*.{xcworkspace,xcodeproj}(N))
fi
local xcode_files
xcode_files=(${1:-.}/{*.{xcworkspace,xcodeproj},Package.swift}(N))
if [[ ${#xcode_proj} -eq 0 ]]; then
if [[ $# == 0 ]]; then
echo "No xcworkspace/xcodeproj file found in the current directory."
else
echo "No xcworkspace/xcodeproj file found in $1."
fi
if [[ ${#xcode_files} -eq 0 ]]; then
echo "No Xcode files found in ${1:-the current directory}." >&2
return 1
else
local active_path
active_path=$(xcode-select -p)
active_path=${active_path%%/Contents/Developer*}
echo "Found ${xcode_proj[1]}. Opening with ${active_path}"
open -a "$active_path" "${xcode_proj[1]}"
fi
local active_path
active_path=${"$(xcode-select -p)"%%/Contents/Developer*}
echo "Found ${xcode_files[1]}. Opening with ${active_path}"
open -a "$active_path" "${xcode_files[1]}"
}
# Opens a file or files in the Xcode IDE. Multiple files are opened in multi-file browser

View file

@ -28,6 +28,7 @@ plugins=(... yarn)
| yi | `yarn init` | Interactively creates or updates a package.json file |
| yin | `yarn install` | Install dependencies defined in `package.json` |
| yln | `yarn lint` | Run the lint script defined in `package.json` |
| ylnf | `yarn lint --fix` | Run the lint script defined in `package.json`to automatically fix problems |
| yls | `yarn list` | List installed packages |
| yout | `yarn outdated` | Check for outdated package dependencies |
| yp | `yarn pack` | Create a compressed gzip archive of package dependencies |

View file

@ -32,15 +32,21 @@
# -------
#
# * Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
# * Shohei YOSHIDA <syohex@gmail.com>
#
# ------------------------------------------------------------------------------
declare -g _yarn_run_cwd
_commands=(
'access'
'audit:Checks for known security issues with the installed packages'
'autoclean:Clean and remove unnecessary files from package dependencies'
'cache:List or clean every cached package'
"check:Verify package dependencies agains yarn's lock file"
"check:Verify package dependencies against yarn's lock file"
'config:Manages the yarn configuration files'
'create:Creates new projects from any create-* starter kits'
'exec'
'generate-lock-entry:Generates a lock file entry'
'global:Install packages globally on your operating system'
'help:Show information about a command'
@ -50,25 +56,30 @@ _commands=(
'install:Install all the dependencies listed within package.json'
'licenses:List licenses for installed packages'
'link:Symlink a package folder during development'
'list:List installed packages'
'login:Store registry username and email'
'logout:Clear registry username and email'
'node:Runs Node with the same version that the one used by Yarn itself'
'outdated:Check for outdated package dependencies'
'owner:Manage package owners'
'pack:Create a compressed gzip archive of package dependencies'
'policies:Defines project-wide policies for your project'
'publish:Publish a package to the npm registry'
'run:Run a defined package script'
'tag:Add, remove, or list tags on a package'
'team:Maintain team memberships'
'unlink:Unlink a previously created symlink for a package'
'unplug:Temporarily copies a package outside of the global cache for debugging purposes'
'version:Update the package version'
'versions:Display version information of currently installed Yarn, Node.js, and its dependencies'
'why:Show information about why a package is installed'
'workspace'
'workspaces:Show information about your workspaces'
)
_global_commands=(
'add:Installs a package and any packages that it depends on'
'bin:Displays the location of the yarn bin folder'
'list:List installed packages'
'remove:Remove installed package from dependencies updating package.json'
'upgrade:Upgrades packages to their latest version based on the specified range'
'upgrade-interactive:Interactively upgrade packages'
@ -76,7 +87,12 @@ _global_commands=(
_yarn_commands_scripts() {
local -a scripts
scripts=($(yarn run --json 2>/dev/null | sed -E '/Commands available|possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n' | sed -e 's/:/\\:/g'))
if [[ -n $opt_args[--cwd] ]]; then
scripts=($(cd $opt_args[--cwd] && yarn run --json 2>/dev/null | sed -E '/Commands available|possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n' | sed -e 's/:/\\:/g'))
else
scripts=($(yarn run --json 2>/dev/null | sed -E '/Commands available|possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n' | sed -e 's/:/\\:/g'))
fi
_describe 'command or script' _commands -- _global_commands -- scripts
}
@ -85,7 +101,11 @@ _yarn_scripts() {
local -a scriptNames scriptCommands
local i runJSON
runJSON=$(yarn run --json 2>/dev/null)
if [[ -n $_yarn_run_cwd ]]; then
runJSON=$(cd $_yarn_run_cwd && yarn run --json 2>/dev/null)
else
runJSON=$(yarn run --json 2>/dev/null)
fi
# Some sed utilities (e.g. Mac OS / BSD) don't interpret `\n` in a replacement
# pattern as a newline. See https://superuser.com/q/307165
binaries=($(sed -E '/Commands available/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\'$'\n/g' <<< "$runJSON"))
@ -96,7 +116,7 @@ _yarn_scripts() {
scripts+=("${scriptNames[$i]}:${scriptCommands[$i]}")
done
commands=($scripts $binaries)
commands=('env' $scripts $binaries)
_describe 'command' commands
}
@ -110,6 +130,17 @@ _yarn_commands() {
_describe 'command' _commands -- _global_commands
}
_yarn_add_files() {
if compset -P "(file|link):"; then
_files
fi
}
_yarn_workspaces() {
local -a workspaces=(${(@f)$(yarn workspaces info |sed -n -e 's/^ "\([^"]*\)": {/\1/p')})
_describe 'workspace' workspaces
}
_yarn() {
local context state state_descr line
typeset -A opt_args
@ -118,37 +149,51 @@ _yarn() {
'(-h --help)'{-h,--help}'[output usage information]' \
'(-V --version)'{-V,--version}'[output the version number]' \
'--verbose[output verbose messages on internal operations]' \
'--offline[trigger an error if any required dependencies are not available in local cache]' \
'--prefer-offline[use network only if dependencies are not available in local cache]' \
'--strict-semver' \
'--json' \
"--ignore-scripts[don't run lifecycle scripts]" \
'--har[save HAR output of network traffic]' \
'--ignore-platform[ignore platform checks]' \
'--ignore-engines[ignore engines check]' \
'--ignore-optional[ignore optional dependencies]' \
'--force[install and build packages even if they were built before, overwrite lockfile]' \
'--skip-integrity-check[run install without checking if node_modules is installed]' \
'--check-files[install will verify file tree of packages for consistency]' \
"--no-bin-links[don't generate bin links when setting up packages]" \
'--flat[only allow one version of a package]' \
'(--prod --production)'{--prod,--production} \
"--no-lockfile[don't read or generate a lockfile]" \
"--pure-lockfile[don't generate a lockfile]" \
"--frozen-lockfile[don't generate a lockfile and fail if an update is needed]" \
'--link-duplicates[create hardlinks to the repeated modules in node_modules]' \
'--global-folder=[modules folder]:folder:_files -/' \
'--modules-folder=[rather than installing modules into the node_modules folder relative to the cwd, output them here]:folder:_files -/' \
'--cache-folder=[specify a custom folder to store the yarn cache]:folder:_files -/' \
'--check-files[install will verify file tree of packages for consistency]' \
'--cwd=[working directory to use]:path:_files -/' \
"(--enable-pnp --pnp)--disable-pnp[disable the Plug'n'Play installation]" \
'(--no-emoji)--emoji=[enable emoji in output(default: false)]:enabled:(true false)' \
'(--emoji)--no-emoji[disable emoji in output]' \
'(--disable-pnp)'{--enable-pnp,--pnp}"[enable the Plug'n'Play installation]" \
'--flat[only allow one version of a package]' \
'--focus[Focus on a single workspace by installing remote copies of its sibiling workspaces]' \
'--force[install and build packages even if they were built before, overwrite lockfile]' \
"--frozen-lockfile[don't generate a lockfile and fail if an update is needed]" \
'--global-folder=[modules folder]:folder:_files -/' \
'--har[save HAR output of network traffic]' \
'--https-proxy=[HTTPS proxy]:host:_hosts' \
'--ignore-engines[ignore engines check]' \
"--ignore-scripts[don't run lifecycle scripts]" \
'--ignore-optional[ignore optional dependencies]' \
'--ignore-platform[ignore platform checks]' \
'--json[format Yarn log messages as lines of JSON]' \
'--link-duplicates[create hardlinks to the repeated modules in node_modules]' \
'--link-folder=[specify a custom folder to store global links]' \
'--modules-folder=[rather than installing modules into the node_modules folder relative to the cwd, output them here]:folder:_files -/' \
'--mutex=[use a mutex to ensure only one yarn instance is executing]:type[\:specifier]' \
'--no-emoji[disable emoji in output]' \
'(-s --silent)'{-s,--silent}'[skip Yarn console logs, other types of logs (script output) will be printed]' \
'--proxy=:host:_hosts' \
'--https-proxy=:host:_hosts' \
'--no-progress[disable progress bar]' \
'--network-concurrency=[maximum number of concurrent network requests]:number' \
'--network-timeout=[TCP timeout for network requests]:milliseconds' \
"--no-bin-links[don't generate bin links when setting up packages]" \
'--no-default-rc[prevent Yarn from automatically detecting yarnrc and npmrc files]' \
"--no-lockfile[don't read or generate a lockfile]" \
'--non-interactive[do not show interactive prompts]' \
'--no-node-version-check[do not warn when using a potentially unsupported Node version]' \
'--no-progress[disable progress bar]' \
'--offline[trigger an error if any required dependencies are not available in local cache]' \
'--otp=[one-time password for two factor authentication]:otpcode' \
'--prefer-offline[use network only if dependencies are not available in local cache]' \
'--preferred-cache-folder=[specify a custom folder to store the yarn cache if possible]:folder:_files -/' \
'(--prod --production)'{--prod,--production}'[install only production dependencies]' \
'--proxy=[HTTP proxy]:host:_hosts' \
"--pure-lockfile[don't generate a lockfile]" \
'--registry=[override configuration registry]:url:_urls' \
'(-s --silent)'{-s,--silent}'[skip Yarn console logs, other types of logs (script output) will be printed]' \
'--scripts-prepend-node-path=[prepend the node executable dir to the PATH in scripts]:bool:(true false)' \
'--skip-integrity-check[run install without checking if node_modules is installed]' \
"--strict-semver[don't compare semver loosely]" \
'--update-checksum[update package checksums from current repository]' \
'--use-yarnrc=[specifies a yarnrc that Yarn should use]:yarnrc:_files' \
'1: :_yarn_commands_scripts' \
'*:: :->command_args'
@ -173,18 +218,29 @@ _yarn() {
'(-O --optional)'{-O,--optional}'[install packages in optionalDependencies]' \
'(-E --exact)'{-E,--exact}'[install packages as exact versions]' \
'(-T --tilde)'{-T,--tilde}'[install the most recent release of the packages that have the same minor version]' \
'*:package-name:'
'(--ignore-workspace-root-check -W)'{--ignore-workspace-root-check,-W}'[allows a package to be installed at the workspaces root]' \
'--audit[checks for known security issues with the installed packages]' \
'*:package-name:_yarn_add_files'
;;
audit)
_arguments \
'--verbose[output verbose message]' \
'--json[format Yarn log messages as lines of JSON]' \
'--level=[only print advisories with severity greater than or equal to]:level:(info low moderate high critical)' \
'--groups=[only audit dependencies from listed groups]:groups:->groups_args'
;;
cache)
_arguments \
'1: :(ls dir clean)'
'1: :(list dir clean)' \
'*:: :->cache_args'
;;
check)
_arguments \
'--integrity' \
'--verify-tree'
'--integrity[Verifies that versions and hashed values of the package contents in package.json]' \
'--verify-tree[Recursively verifies that the dependencies in package.json are present in node_modules]'
;;
config)
@ -223,12 +279,13 @@ _yarn() {
list)
_arguments \
'--depth[Limit the depth of the shown dependencies]:depth'
'--depth=[Limit the depth of the shown dependencies]:depth' \
'--pattern=[filter the list of dependencies by the pattern]'
;;
owner)
_arguments \
'1: :(ls add rm)' \
'1: :(list add rm)' \
'*:: :->owner_args'
;;
@ -247,12 +304,22 @@ _yarn() {
'1: :_files'
;;
policies)
_arguments \
'1: :(set-version)'
;;
remove|upgrade)
_arguments \
'*:package:'
;;
run)
if [[ -n $opt_args[--cwd] ]]; then
_yarn_run_cwd=$opt_args[--cwd]
else
_yarn_run_cwd=''
fi
_arguments \
'1: :_yarn_scripts' \
'*:: :_default'
@ -260,26 +327,33 @@ _yarn() {
tag)
_arguments \
'1: :(ls add rm)' \
'1: :(lists add rm)' \
'*:: :->tag_args'
;;
team)
_arguments \
'1: :(create destroy add rm ls)' \
'1: :(create destroy add rm list)' \
'*:: :->team_args'
;;
upgrade-interactive)
_arguments \
'--latest:use the version tagged latest in the registry:'
'--latest[use the version tagged latest in the registry]'
;;
version)
_arguments \
'--new-version:version:' \
'--message:message:' \
'--no-git-tag-version'
'--new-version[create a new version using an interactive session to prompt you]:version:' \
'--major[creates a new version by incrementing the major version]' \
'--minor[creates a new version by incrementing the minor version]' \
'--patch[creates a new version by incrementing the patch version]' \
'--premajor[creates a new prerelease version by incrementing the major version]' \
'--preminor[creates a new prerelease version by incrementing the minor version]' \
'--prepatch[creates a new prerelease version by incrementing the patch version]' \
'--prerelease[increments the prerelease version number keeping the main version]' \
'--no-git-tag-version[creates a new version without creating a git tag]' \
'--no-commit-hooks[bypasses running commit hooks when committing the new version]'
;;
why)
@ -287,7 +361,19 @@ _yarn() {
'1:query:_files'
;;
*)
workspace)
_arguments \
'1:workspace:_yarn_workspaces' \
'*:: :_yarn_global_commands'
;;
workspaces)
_arguments \
'--json[format Yarn log messages as lines of JSON]' \
'1:commands:(info run)'
;;
*)
_default
;;
esac
@ -295,6 +381,12 @@ _yarn() {
esac
case $state in
cache_args)
if [[ $words[1] == "list" ]]; then
_arguments \
'--pattern=[print out every cached package that matches the pattern]:pattern:'
fi
;;
config_args)
case $words[1] in
get|delete)
@ -310,6 +402,10 @@ _yarn() {
;;
esac
;;
groups_args)
local dependency_groups=(devDependencies dependencies optionalDependencies peerDependencies bundledDependencies)
_values -s ',' 'groups' $dependency_groups
;;
owner_args)
case $words[1] in

View file

@ -1,3 +1,10 @@
# Add yarn bin directory to $PATH if it exists and not in $PATH already
bindir=$(yarn global bin 2>/dev/null) \
&& [[ -d "$bindir" ]] \
&& (( ! ${path[(Ie)$bindir]} )) \
&& path+=("$bindir")
unset bindir
alias y="yarn"
alias ya="yarn add"
alias yad="yarn add --dev"
@ -13,6 +20,7 @@ alias yh="yarn help"
alias yi="yarn init"
alias yin="yarn install"
alias yln="yarn lint"
alias ylnf="yarn lint --fix"
alias yls="yarn list"
alias yout="yarn outdated"
alias yp="yarn pack"

View file

@ -42,6 +42,8 @@ _z() {
[ -z "$_Z_OWNER" -a -f "$datafile" -a ! -O "$datafile" ] && return
_z_dirs () {
[ -f "$datafile" ] || return
local line
while read line; do
# only count directories
@ -54,14 +56,16 @@ _z() {
if [ "$1" = "--add" ]; then
shift
# $HOME isn't worth matching
[ "$*" = "$HOME" ] && return
# $HOME and / aren't worth matching
[ "$*" = "$HOME" -o "$*" = '/' ] && return
# don't track excluded directory trees
local exclude
for exclude in "${_Z_EXCLUDE_DIRS[@]}"; do
case "$*" in "$exclude*") return;; esac
done
if [ ${#_Z_EXCLUDE_DIRS[@]} -gt 0 ]; then
local exclude
for exclude in "${_Z_EXCLUDE_DIRS[@]}"; do
case "$*" in "$exclude"*) return;; esac
done
fi
# maintain the data file
local tempfile="$datafile.$RANDOM"

View file

@ -1,23 +1,3 @@
# zsh_reload plugin
The zsh_reload plugin defines a function to reload the zsh session with
just a few keystrokes.
To use it, add `zsh_reload` to the plugins array in your zshrc file:
```zsh
plugins=(... zsh_reload)
```
## Usage
To reload the zsh session, just run `src`:
```zsh
$ vim ~/.zshrc # enabled a plugin
$ src
re-compiling /home/user/.zshrc.zwc: succeeded
re-compiling /home/user/.oh-my-zsh/cache/zcomp-host.zwc: succeeded
# you now have a fresh zsh session. happy hacking!
```
**This plugin is deprecated.** Use `omz reload` or `exec zsh` instead.

View file

@ -1,22 +1,7 @@
print ${(%):-"%F{yellow}The \`zsh_reload\` plugin is deprecated and will be removed."}
print ${(%):-"Use \`%Bomz reload%b\` or \`%Bexec zsh%b\` instead.%f"}
src() {
local cache="$ZSH_CACHE_DIR"
autoload -U compinit zrecompile
compinit -i -d "$cache/zcomp-$HOST"
for f in ${ZDOTDIR:-~}/.zshrc "$cache/zcomp-$HOST"; do
zrecompile -p $f && command rm -f $f.zwc.old
done
# Use $SHELL if it's available and a zsh shell
local shell="$ZSH_ARGZERO"
if [[ "${${SHELL:t}#-}" = zsh ]]; then
shell="$SHELL"
fi
# Remove leading dash if login shell and run accordingly
if [[ "${shell:0:1}" = "-" ]]; then
exec -l "${shell#-}"
else
exec "$shell"
fi
print ${(%):-"%F{yellow}$0 is deprecated. Use \`%Bomz reload%b\` or \`%Bexec zsh%b\` instead.%f\n"}
omz reload
}

View file

@ -23,14 +23,13 @@ ZSH_THEME="robbyrussell"
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"
# Uncomment one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled # disable automatic updates
# zstyle ':omz:update' mode auto # update automatically without asking
# zstyle ':omz:update' mode reminder # just remind me to update when it's time
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# zstyle ':omz:update' frequency 13
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

View file

@ -51,9 +51,9 @@ root_prompt="$emoji[skull]"
warn_prompt="$emoji[collision_symbol]"
vcs_unstaged_glyph="%{$emoji[circled_latin_capital_letter_m]$emoji2[emoji_style] %2G%}"
vcs_staged_glyph="%{$emoji[high_voltage_sign] %2G%}"
vcs_branch_glyph=$(print -P $'\Ue0a0') # 
vcs_action_glyph=$(print -P $'\U276f') #
vcs_staged_glyph="%{$emoji[high_voltage_sign]%2G%}"
vcs_branch_glyph=$'\Ue0a0' # 
vcs_action_glyph=$'\U276f' #
red="$FG[001]"
yellow="$FG[003]"

View file

@ -2,10 +2,9 @@ if [ "$USERNAME" = "root" ]; then CARETCOLOR="red"; else CARETCOLOR="blue"; fi
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
PROMPT='%{$fg[green]%}[%*]%{$reset_color%} %{$fg_no_bold[cyan]%}%n %{${fg_bold[blue]}%}::%{$reset_color%} %{$fg[yellow]%}%m%{$reset_color%} %{$fg_no_bold[magenta]%} ➜ %{$reset_color%} %{${fg[green]}%}%3~ $(git_prompt_info)%{${fg_bold[$CARETCOLOR]}%}»%{${reset_color}%} '
PROMPT='%{$fg[green]%}[%D{%H:%M:%S}]%{$reset_color%} %{$fg_no_bold[cyan]%}%n %{${fg_bold[blue]}%}::%{$reset_color%} %{$fg[yellow]%}%m%{$reset_color%} %{$fg_no_bold[magenta]%} ➜ %{$reset_color%} %{${fg[green]}%}%3~ $(git_prompt_info)%{${fg_bold[$CARETCOLOR]}%}»%{${reset_color}%} '
RPS1="${return_code}"
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX=" %{$reset_color%}"

View file

@ -35,19 +35,20 @@ prompt_setup_pygmalion(){
}
prompt_pygmalion_precmd(){
setopt localoptions extendedglob
setopt localoptions nopromptsubst extendedglob
local gitinfo=$(git_prompt_info)
local gitinfo_nocolor=${gitinfo//\%\{[^\}]##\}}
local exp_nocolor="$(print -P \"$base_prompt_nocolor$gitinfo_nocolor$post_prompt_nocolor\")"
local exp_nocolor="$(print -P \"${base_prompt_nocolor}${gitinfo_nocolor}${post_prompt_nocolor}\")"
local prompt_length=${#exp_nocolor}
# add new line on prompt longer than 40 characters
local nl=""
if [[ $prompt_length -gt 40 ]]; then
nl=$'\n%{\r%}';
nl=$'\n%{\r%}'
fi
PROMPT="$base_prompt$gitinfo$nl$post_prompt"
PROMPT="${base_prompt}\$(git_prompt_info)${nl}${post_prompt}"
}
prompt_setup_pygmalion

View file

@ -19,14 +19,14 @@ prompt_setup_pygmalion(){
}
prompt_pygmalion_precmd(){
setopt localoptions extendedglob
setopt localoptions nopromptsubst extendedglob
local gitinfo=$(git_prompt_info)
local gitinfo_nocolor=${gitinfo//\%\{[^\}]##\}}
local exp_nocolor="$(print -P \"$base_prompt_nocolor$gitinfo_nocolor$post_prompt_nocolor\")"
local exp_nocolor="$(print -P \"${base_prompt_nocolor}${gitinfo_nocolor}${post_prompt_nocolor}\")"
local prompt_length=${#exp_nocolor}
PROMPT="${base_prompt}${gitinfo}${post_prompt}"
PROMPT="${base_prompt}\$(git_prompt_info)${post_prompt}"
}
prompt_setup_pygmalion

View file

@ -33,8 +33,8 @@ autoload -Uz vcs_info
zstyle ':vcs_info:*' enable hg bzr git
zstyle ':vcs_info:*:*' unstagedstr '!'
zstyle ':vcs_info:*:*' stagedstr '+'
zstyle ':vcs_info:*:*' formats "$FX[bold]%r$FX[no-bold]/%S" "%s/%b" "%%u%c"
zstyle ':vcs_info:*:*' actionformats "$FX[bold]%r$FX[no-bold]/%S" "%s/%b" "%u%c (%a)"
zstyle ':vcs_info:*:*' formats "$FX[bold]%r$FX[no-bold]/%S" "%s:%b" "%%u%c"
zstyle ':vcs_info:*:*' actionformats "$FX[bold]%r$FX[no-bold]/%S" "%s:%b" "%u%c (%a)"
zstyle ':vcs_info:*:*' nvcsformats "%~" "" ""
# Fastest possible way to check if repo is dirty
@ -70,6 +70,7 @@ preexec() {
# Output additional information about paths, repos and exec time
#
precmd() {
setopt localoptions nopromptsubst
vcs_info # Get version control info before we start outputting stuff
print -P "\n$(repo_information) %F{yellow}$(cmd_exec_time)%f"
unset cmd_timestamp #Reset cmd exec time.

View file

@ -5,8 +5,10 @@
#
# Mar 2013 Yad Smood
typeset +H my_gray="$FG[247]"
# VCS
YS_VCS_PROMPT_PREFIX1=" %{$fg[white]%}on%{$reset_color%} "
YS_VCS_PROMPT_PREFIX1=" %{$my_gray%}on%{$reset_color%} "
YS_VCS_PROMPT_PREFIX2=":%{$fg[cyan]%}"
YS_VCS_PROMPT_SUFFIX="%{$reset_color%}"
YS_VCS_PROMPT_DIRTY=" %{$fg[red]%}x"
@ -60,13 +62,13 @@ local exit_code="%(?,,C:%{$fg[red]%}%?%{$reset_color%})"
PROMPT="
%{$terminfo[bold]$fg[blue]%}#%{$reset_color%} \
%(#,%{$bg[yellow]%}%{$fg[black]%}%n%{$reset_color%},%{$fg[cyan]%}%n) \
%{$fg[white]%}@ \
%{$my_gray%}@ \
%{$fg[green]%}%m \
%{$fg[white]%}in \
%{$my_gray%}in \
%{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\
${hg_info}\
${git_info}\
${venv_info}\
\
%{$fg[white]%}[%*] $exit_code
%{$my_gray%}[%*] $exit_code
%{$terminfo[bold]$fg[red]%}$ %{$reset_color%}"

View file

@ -1,5 +1,8 @@
#!/usr/bin/env zsh
cd "$ZSH"
setopt extendedglob
##############################
# CHANGELOG SCRIPT CONSTANTS #
##############################
@ -49,10 +52,15 @@ function parse-commit {
# make a breaking change
function commit:type {
local type="$(sed -E 's/^([a-zA-Z_\-]+)(\(.+\))?!?: .+$/\1/' <<< "$1")"
local type
# Parse commit type from the subject
if [[ "$1" =~ '^([a-zA-Z_\-]+)(\(.+\))?!?: .+$' ]]; then
type="${match[1]}"
fi
# If $type doesn't appear in $TYPES array mark it as 'other'
if [[ -n "${(k)TYPES[(i)$type]}" ]]; then
if [[ -n "$type" && -n "${(k)TYPES[(i)$type]}" ]]; then
echo $type
else
echo other
@ -63,17 +71,18 @@ function parse-commit {
local scope
# Try to find scope in "type(<scope>):" format
scope=$(sed -nE 's/^[a-zA-Z_\-]+\((.+)\)!?: .+$/\1/p' <<< "$1")
if [[ -n "$scope" ]]; then
echo "$scope"
if [[ "$1" =~ '^[a-zA-Z_\-]+\((.+)\)!?: .+$' ]]; then
echo "${match[1]}"
return
fi
# If no scope found, try to find it in "<scope>:" format
# Make sure it's not a type before printing it
scope=$(sed -nE 's/^([a-zA-Z_\-]+): .+$/\1/p' <<< "$1")
if [[ -z "${(k)TYPES[(i)$scope]}" ]]; then
echo "$scope"
if [[ "$1" =~ '^([a-zA-Z_\-]+): .+$' ]]; then
scope="${match[1]}"
# Make sure it's not a type before printing it
if [[ -z "${(k)TYPES[(i)$scope]}" ]]; then
echo "$scope"
fi
fi
}
@ -81,7 +90,11 @@ function parse-commit {
# Only display the relevant part of the commit, i.e. if it has the format
# type[(scope)!]: subject, where the part between [] is optional, only
# displays subject. If it doesn't match the format, returns the whole string.
sed -E 's/^[a-zA-Z_\-]+(\(.+\))?!?: (.+)$/\2/' <<< "$1"
if [[ "$1" =~ '^[a-zA-Z_\-]+(\(.+\))?!?: (.+)$' ]]; then
echo "${match[2]}"
else
echo "$1"
fi
}
# Return subject if the body or subject match the breaking change format
@ -114,15 +127,8 @@ function parse-commit {
fi
}
# Ignore commit if it is a merge commit
if [[ $(command git show -s --format=%p $1 | wc -w) -gt 1 ]]; then
return
fi
# Parse commit with hash $1
local hash="$1" subject body warning rhash
subject="$(command git show -s --format=%s $hash)"
body="$(command git show -s --format=%b $hash)"
local hash="$1" subject="$2" body="$3" warning rhash
# Commits following Conventional Commits (https://www.conventionalcommits.org/)
# have the following format, where parts between [] are optional:
@ -195,9 +201,9 @@ function display-release {
#* Uses $hash from outer scope
local hash="${1:-$hash}"
case "$output" in
raw) printf "$hash" ;;
text) printf "\e[33m$hash\e[0m" ;; # red
md) printf "[\`$hash\`](https://github.com/ohmyzsh/ohmyzsh/commit/$hash)" ;;
raw) printf '%s' "$hash" ;;
text) printf '\e[33m%s\e[0m' "$hash" ;; # red
md) printf '[`%s`](https://github.com/ohmyzsh/ohmyzsh/commit/%s)' "$hash" ;;
esac
}
@ -209,16 +215,16 @@ function display-release {
case "$output" in
raw)
case "$level" in
1) printf "$header\n$(printf '%.0s=' {1..${#header}})\n\n" ;;
2) printf "$header\n$(printf '%.0s-' {1..${#header}})\n\n" ;;
*) printf "$header:\n\n" ;;
1) printf '%s\n%s\n\n' "$header" "$(printf '%.0s=' {1..${#header}})" ;;
2) printf '%s\n%s\n\n' "$header" "$(printf '%.0s-' {1..${#header}})" ;;
*) printf '%s:\n\n' "$header" ;;
esac ;;
text)
case "$level" in
1|2) printf "\e[1;4m$header\e[0m\n\n" ;; # bold, underlined
*) printf "\e[1m$header:\e[0m\n\n" ;; # bold
1|2) printf '\e[1;4m%s\e[0m\n\n' "$header" ;; # bold, underlined
*) printf '\e[1m%s:\e[0m\n\n' "$header" ;; # bold
esac ;;
md) printf "$(printf '%.0s#' {1..${level}}) $header\n\n" ;;
md) printf '%s %s\n\n' "$(printf '%.0s#' {1..${level}})" "$header" ;;
esac
}
@ -244,8 +250,8 @@ function display-release {
# Print [scope]
case "$output" in
raw|md) printf "[$scope]${padding} " ;;
text) printf "[\e[38;5;9m$scope\e[0m]${padding} " ;; # red 9
raw|md) printf '[%s]%s ' "$scope" "$padding";;
text) printf '[\e[38;5;9m%s\e[0m]%s ' "$scope" "$padding";; # red 9
esac
}
@ -258,7 +264,7 @@ function display-release {
subject="${(U)subject:0:1}${subject:1}"
case "$output" in
raw) printf "$subject" ;;
raw) printf '%s' "$subject" ;;
# In text mode, highlight (#<issue>) and dim text between `backticks`
text) sed -E $'s|#([0-9]+)|\e[32m#\\1\e[0m|g;s|`([^`]+)`|`\e[2m\\1\e[0m`|g' <<< "$subject" ;;
# In markdown mode, link to (#<issue>) issues
@ -271,8 +277,8 @@ function display-release {
local type="${1:-${TYPES[$type]:-${(C)type}}}"
[[ -z "$type" ]] && return 0
case "$output" in
raw|md) printf "$type: " ;;
text) printf "\e[4m$type\e[24m: " ;; # underlined
raw|md) printf '%s: ' "$type" ;;
text) printf '\e[4m%s\e[24m: ' "$type" ;; # underlined
esac
}
@ -286,7 +292,7 @@ function display-release {
(( $#breaking != 0 )) || return 0
case "$output" in
text) fmt:header "\e[31mBREAKING CHANGES" 3 ;;
text) printf '\e[31m'; fmt:header "BREAKING CHANGES" 3 ;;
raw) fmt:header "BREAKING CHANGES" 3 ;;
md) fmt:header "BREAKING CHANGES ⚠" 3 ;;
esac
@ -384,7 +390,8 @@ function main {
# Commit classification arrays
local -A commits subjects scopes breaking reverts
local truncate=0 read_commits=0
local hash version tag
local version tag
local hash refs subject body
# Get the first version name:
# 1) try tag-like version, or
@ -396,17 +403,41 @@ function main {
|| version=$(command git symbolic-ref --quiet --short $until 2>/dev/null) \
|| version=$(command git rev-parse --short $until 2>/dev/null)
# Get commit list from $until commit until $since commit, or until root
# commit if $since is unset, in short hash form.
command git rev-list --abbrev-commit --abbrev=7 ${since:+$since..}$until | while read hash; do
# Get commit list from $until commit until $since commit, or until root commit if $since is unset
local range=${since:+$since..}$until
# Git log options
# -z: commits are delimited by null bytes
# --format: [7-char hash]<field sep>[ref names]<field sep>[subject]<field sep>[body]
# --abbrev=7: force commit hashes to be 7 characters long
# --no-merges: merge commits are omitted
# --first-parent: commits from merged branches are omitted
local SEP="0mZmAgIcSeP"
local -a raw_commits
raw_commits=(${(0)"$(command git log -z \
--format="%h${SEP}%D${SEP}%s${SEP}%b" --abbrev=7 \
--no-merges --first-parent $range)"})
local raw_commit
local -a raw_fields
for raw_commit in $raw_commits; do
# Truncate list on versions with a lot of commits
if [[ -z "$since" ]] && (( ++read_commits > 35 )); then
truncate=1
break
fi
# Read the commit fields (@ is needed to keep empty values)
eval "raw_fields=(\"\${(@ps:$SEP:)raw_commit}\")"
hash="${raw_fields[1]}"
refs="${raw_fields[2]}"
subject="${raw_fields[3]}"
body="${raw_fields[4]}"
# If we find a new release (exact tag)
if tag=$(command git describe --exact-match --tags $hash 2>/dev/null); then
if [[ "$refs" = *tag:\ * ]]; then
# Parse tag name (needs: setopt extendedglob)
tag="${${refs##*tag: }%%,# *}"
# Output previous release
display-release
# Reinitialize commit storage
@ -420,7 +451,7 @@ function main {
read_commits=1
fi
parse-commit "$hash"
parse-commit "$hash" "$subject" "$body"
done
display-release
@ -431,8 +462,6 @@ function main {
fi
}
cd "$ZSH"
# Use raw output if stdout is not a tty
if [[ ! -t 1 && -z "$3" ]]; then
main "$1" "$2" --raw

View file

@ -3,22 +3,80 @@ if [[ -f ~/.zsh-update && ! -f "${ZSH_CACHE_DIR}/.zsh-update" ]]; then
mv ~/.zsh-update "${ZSH_CACHE_DIR}/.zsh-update"
fi
# Get user's update preferences
#
# Supported update modes:
# - prompt (default): the user is asked before updating when it's time to update
# - auto: the update is performed automatically when it's time
# - reminder: a reminder is shown to the user when it's time to update
# - disabled: automatic update is turned off
zstyle -s ':omz:update' mode update_mode || update_mode=prompt
# Support old-style settings
[[ "$DISABLE_UPDATE_PROMPT" != true ]] || update_mode=auto
[[ "$DISABLE_AUTO_UPDATE" != true ]] || update_mode=disabled
# Cancel update if:
# - the automatic update is disabled.
# - the current user doesn't have write permissions nor owns the $ZSH directory.
# - git is unavailable on the system.
if [[ "$DISABLE_AUTO_UPDATE" = true ]] \
if [[ "$update_mode" = disabled ]] \
|| [[ ! -w "$ZSH" || ! -O "$ZSH" ]] \
|| ! command -v git &>/dev/null; then
unset update_mode
return
fi
function current_epoch() {
zmodload zsh/datetime
echo $(( EPOCHSECONDS / 60 / 60 / 24 ))
}
function is_update_available() {
local branch
branch=${"$(cd "$ZSH"; git config --local oh-my-zsh.branch)":-master}
local remote remote_url remote_repo
remote=${"$(cd "$ZSH"; git config --local oh-my-zsh.remote)":-origin}
remote_url=$(cd "$ZSH"; git config remote.$remote.url)
local repo
case "$remote_url" in
https://github.com/*) repo=${${remote_url#https://github.com/}%.git} ;;
git@github.com:*) repo=${${remote_url#git@github.com:}%.git} ;;
*)
# If the remote is not using GitHub we can't check for updates
# Let's assume there are updates
return 0 ;;
esac
# If the remote repo is not the official one, let's assume there are updates available
[[ "$repo" = ohmyzsh/ohmyzsh ]] || return 0
local api_url="https://api.github.com/repos/${repo}/commits/${branch}"
# Get local HEAD. If this fails assume there are updates
local local_head
local_head=$(cd "$ZSH"; git rev-parse $branch 2>/dev/null) || return 0
# Get remote HEAD. If no suitable command is found assume there are updates
# On any other error, skip the update (connection may be down)
local remote_head
remote_head=$(
if (( ${+commands[curl]} )); then
curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null
elif (( ${+commands[wget]} )); then
wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null
elif (( ${+commands[fetch]} )); then
HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null
else
exit 0
fi
) || return 1
# Compare local and remote HEADs
[[ "$local_head" != "$remote_head" ]]
}
function update_last_updated_file() {
echo "LAST_EPOCH=$(current_epoch)" >! "${ZSH_CACHE_DIR}/.zsh-update"
}
@ -56,7 +114,8 @@ function update_ohmyzsh() {
# the shell actually exits what it's running.
trap "
ret=\$?
unset -f current_epoch update_last_updated_file update_ohmyzsh 2>/dev/null
unset update_mode
unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh 2>/dev/null
command rm -rf '$ZSH/log/update.lock'
return \$ret
" EXIT INT QUIT
@ -68,15 +127,22 @@ function update_ohmyzsh() {
fi
# Number of days before trying to update again
epoch_target=${UPDATE_ZSH_DAYS:-13}
zstyle -s ':omz:update' frequency epoch_target || epoch_target=${UPDATE_ZSH_DAYS:-13}
# Test if enough time has passed until the next update
if (( ( $(current_epoch) - $LAST_EPOCH ) < $epoch_target )); then
return
fi
# Ask for confirmation before updating unless disabled
if [[ "$DISABLE_UPDATE_PROMPT" = true ]]; then
# Check if there are updates available before proceeding
if ! is_update_available; then
return
fi
# Ask for confirmation before updating unless in auto mode
if [[ "$update_mode" = auto ]]; then
update_ohmyzsh
elif [[ "$update_mode" = reminder ]]; then
echo "[oh-my-zsh] It's time to update! You can do that by running \`omz update\`"
else
# input sink to swallow all characters typed before the prompt
# and add a newline if there wasn't one after characters typed
@ -92,3 +158,6 @@ function update_ohmyzsh() {
esac
fi
}
unset update_mode
unset -f current_epoch is_update_available update_last_updated_file update_ohmyzsh

View file

@ -311,7 +311,7 @@ EOF
# 1. Use the most preceding one based on $PATH, then check that it's in the shells file
# 2. If that fails, get a zsh path from the shells file, then check it actually exists
if ! zsh=$(command -v zsh) || ! grep -qx "$zsh" "$shells_file"; then
if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -1) || [ ! -f "$zsh" ]; then
if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -n 1) || [ ! -f "$zsh" ]; then
fmt_error "no zsh binary found or not present in '$shells_file'"
fmt_error "change your default shell manually."
return

View file

@ -15,11 +15,98 @@ cd "$ZSH"
# Use colors, but only if connected to a terminal
# and that terminal supports them.
# The [ -t 1 ] check only works when the function is not called from
# a subshell (like in `$(...)` or `(...)`, so this hack redefines the
# function at the top level to always return false when stdout is not
# a tty.
if [ -t 1 ]; then
is_tty() {
true
}
else
is_tty() {
false
}
fi
# This function uses the logic from supports-hyperlinks[1][2], which is
# made by Kat Marchán (@zkat) and licensed under the Apache License 2.0.
# [1] https://github.com/zkat/supports-hyperlinks
# [2] https://crates.io/crates/supports-hyperlinks
#
# Copyright (c) 2021 Kat Marchán
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
supports_hyperlinks() {
# $FORCE_HYPERLINK must be set and be non-zero (this acts as a logic bypass)
if [ -n "$FORCE_HYPERLINK" ]; then
[ "$FORCE_HYPERLINK" != 0 ]
return $?
fi
# If stdout is not a tty, it doesn't support hyperlinks
is_tty || return 1
# DomTerm terminal emulator (domterm.org)
if [ -n "$DOMTERM" ]; then
return 0
fi
# VTE-based terminals above v0.50 (Gnome Terminal, Guake, ROXTerm, etc)
if [ -n "$VTE_VERSION" ]; then
[ $VTE_VERSION -ge 5000 ]
return $?
fi
# If $TERM_PROGRAM is set, these terminals support hyperlinks
case "$TERM_PROGRAM" in
Hyper|iTerm.app|terminology|WezTerm) return 0 ;;
esac
# kitty supports hyperlinks
if [ "$TERM" = xterm-kitty ]; then
return 0
fi
# Windows Terminal or Konsole also support hyperlinks
if [ -n "$WT_SESSION" ] || [ -n "$KONSOLE_VERSION" ]; then
return 0
fi
return 1
}
fmt_link() {
# $1: text, $2: url, $3: fallback mode
if supports_hyperlinks; then
printf '\033]8;;%s\a%s\033]8;;\a\n' "$2" "$1"
return
fi
case "$3" in
--text) printf '%s\n' "$1" ;;
--url|*) fmt_underline "$2" ;;
esac
}
fmt_underline() {
is_tty && printf '\033[4m%s\033[24m\n' "$*" || printf '%s\n' "$*"
}
setopt typeset_silent
typeset -a RAINBOW
typeset RED GREEN YELLOW BLUE BOLD DIM UNDER RESET
if [ -t 1 ]; then
if is_tty; then
RAINBOW=(
"$(printf '\033[38;5;196m')"
"$(printf '\033[38;5;202m')"
@ -35,8 +122,6 @@ if [ -t 1 ]; then
YELLOW=$(printf '\033[33m')
BLUE=$(printf '\033[34m')
BOLD=$(printf '\033[1m')
DIM=$(printf '\033[2m')
UNDER=$(printf '\033[4m')
RESET=$(printf '\033[0m')
fi
@ -104,10 +189,10 @@ if git pull --rebase --stat $remote $branch; then
printf '%s\____/%s_/ /_/ %s /_/ /_/ /_/%s\__, / %s /___/%s____/%s_/ /_/ %s\n' $RAINBOW $RESET
printf '%s %s %s %s /____/ %s %s %s %s\n' $RAINBOW $RESET
printf '\n'
printf "${BLUE}%s${RESET}\n" "$message"
printf "${BLUE}${BOLD}%s ${UNDER}%s${RESET}\n" "To keep up with the latest news and updates, follow us on Twitter:" "https://twitter.com/ohmyzsh"
printf "${BLUE}${BOLD}%s ${UNDER}%s${RESET}\n" "Want to get involved in the community? Join our Discord:" "https://discord.gg/ohmyzsh"
printf "${BLUE}${BOLD}%s ${UNDER}%s${RESET}\n" "Get your Oh My Zsh swag at:" "https://shop.planetargon.com/collections/oh-my-zsh"
printf "${BLUE}%s${RESET}\n\n" "$message"
printf "${BLUE}${BOLD}%s %s${RESET}\n" "To keep up with the latest news and updates, follow us on Twitter:" "$(fmt_link @ohmyzsh https://twitter.com/ohmyzsh)"
printf "${BLUE}${BOLD}%s %s${RESET}\n" "Want to get involved in the community? Join our Discord:" "$(fmt_link "Discord server" https://discord.gg/ohmyzsh)"
printf "${BLUE}${BOLD}%s %s${RESET}\n" "Get your Oh My Zsh swag at:" "$(fmt_link "Planet Argon Shop" https://shop.planetargon.com/collections/oh-my-zsh)"
else
ret=$?
printf "${RED}%s${RESET}\n" 'There was an error updating. Try again later?'