mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-23 22:30:07 +00:00
Merge branch 'ohmyzsh:master' into master
This commit is contained in:
commit
caf9c3bd6d
31 changed files with 339 additions and 153 deletions
12
.github/workflows/project.yml
vendored
12
.github/workflows/project.yml
vendored
|
@ -47,21 +47,25 @@ jobs:
|
||||||
ISSUE_OR_PR_ID: ${{ github.event.issue.node_id || github.event.pull_request.node_id }}
|
ISSUE_OR_PR_ID: ${{ github.event.issue.node_id || github.event.pull_request.node_id }}
|
||||||
run: |
|
run: |
|
||||||
item_id="$(gh api graphql -f query='
|
item_id="$(gh api graphql -f query='
|
||||||
mutation($project: ID!, $item: ID!) {
|
mutation($project: ID!, $content: ID!) {
|
||||||
addProjectNextItem(input: {projectId: $project, contentId: $item}) {
|
addProjectNextItem(input: {projectId: $project, contentId: $content}) {
|
||||||
projectNextItem {
|
projectNextItem {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
' -f project=$PROJECT_ID -f item=$ISSUE_OR_PR_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
|
' -f project=$PROJECT_ID -f content=$ISSUE_OR_PR_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
|
||||||
|
|
||||||
echo "ITEM_ID=$item_id" >> $GITHUB_ENV
|
echo "ITEM_ID=$item_id" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Classify Pull Request
|
- name: Classify Pull Request
|
||||||
if: github.event_name == 'pull_request_target'
|
if: github.event_name == 'pull_request_target'
|
||||||
run: |
|
run: |
|
||||||
gh pr view ${{ github.event.pull_request.number }} --json files --jq '.files.[].path' | awk -F/ '
|
touch plugins.list themes.list
|
||||||
|
|
||||||
|
gh pr view ${{ github.event.pull_request.number }} \
|
||||||
|
--repo ${{ github.repository }} \
|
||||||
|
--json files --jq '.files.[].path' | awk -F/ '
|
||||||
/^plugins\// {
|
/^plugins\// {
|
||||||
plugins[$2] = 1
|
plugins[$2] = 1
|
||||||
}
|
}
|
||||||
|
|
59
lib/cli.zsh
59
lib/cli.zsh
|
@ -37,7 +37,7 @@ function _omz {
|
||||||
elif (( CURRENT == 3 )); then
|
elif (( CURRENT == 3 )); then
|
||||||
case "$words[2]" in
|
case "$words[2]" in
|
||||||
changelog) local -a refs
|
changelog) local -a refs
|
||||||
refs=("${(@f)$(cd "$ZSH"; command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
|
refs=("${(@f)$(builtin cd -q "$ZSH"; command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
|
||||||
_describe 'command' refs ;;
|
_describe 'command' refs ;;
|
||||||
plugin) subcmds=(
|
plugin) subcmds=(
|
||||||
'disable:Disable plugin(s)'
|
'disable:Disable plugin(s)'
|
||||||
|
@ -61,7 +61,7 @@ function _omz {
|
||||||
# if command is "disable", only offer already enabled plugins
|
# if command is "disable", only offer already enabled plugins
|
||||||
valid_plugins=($plugins)
|
valid_plugins=($plugins)
|
||||||
else
|
else
|
||||||
valid_plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(.N:h:t))
|
valid_plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t))
|
||||||
# if command is "enable", remove already enabled plugins
|
# if command is "enable", remove already enabled plugins
|
||||||
[[ "${words[3]}" = enable ]] && valid_plugins=(${valid_plugins:|plugins})
|
[[ "${words[3]}" = enable ]] && valid_plugins=(${valid_plugins:|plugins})
|
||||||
fi
|
fi
|
||||||
|
@ -69,11 +69,11 @@ function _omz {
|
||||||
_describe 'plugin' valid_plugins ;;
|
_describe 'plugin' valid_plugins ;;
|
||||||
plugin::info)
|
plugin::info)
|
||||||
local -aU plugins
|
local -aU plugins
|
||||||
plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(.N:h:t))
|
plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t))
|
||||||
_describe 'plugin' plugins ;;
|
_describe 'plugin' plugins ;;
|
||||||
theme::(set|use))
|
theme::(set|use))
|
||||||
local -aU themes
|
local -aU themes
|
||||||
themes=("$ZSH"/themes/*.zsh-theme(.N:t:r) "$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::))
|
themes=("$ZSH"/themes/*.zsh-theme(-.N:t:r) "$ZSH_CUSTOM"/**/*.zsh-theme(-.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::))
|
||||||
_describe 'theme' themes ;;
|
_describe 'theme' themes ;;
|
||||||
esac
|
esac
|
||||||
elif (( CURRENT > 4 )); then
|
elif (( CURRENT > 4 )); then
|
||||||
|
@ -85,7 +85,7 @@ function _omz {
|
||||||
# if command is "disable", only offer already enabled plugins
|
# if command is "disable", only offer already enabled plugins
|
||||||
valid_plugins=($plugins)
|
valid_plugins=($plugins)
|
||||||
else
|
else
|
||||||
valid_plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(.N:h:t))
|
valid_plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t))
|
||||||
# if command is "enable", remove already enabled plugins
|
# if command is "enable", remove already enabled plugins
|
||||||
[[ "${words[3]}" = enable ]] && valid_plugins=(${valid_plugins:|plugins})
|
[[ "${words[3]}" = enable ]] && valid_plugins=(${valid_plugins:|plugins})
|
||||||
fi
|
fi
|
||||||
|
@ -176,13 +176,13 @@ function _omz::changelog {
|
||||||
local version=${1:-HEAD} format=${3:-"--text"}
|
local version=${1:-HEAD} format=${3:-"--text"}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
cd "$ZSH"
|
builtin cd -q "$ZSH"
|
||||||
! command git show-ref --verify refs/heads/$version && \
|
! command git show-ref --verify refs/heads/$version && \
|
||||||
! command git show-ref --verify refs/tags/$version && \
|
! command git show-ref --verify refs/tags/$version && \
|
||||||
! command git rev-parse --verify "${version}^{commit}"
|
! command git rev-parse --verify "${version}^{commit}"
|
||||||
) &>/dev/null; then
|
) &>/dev/null; then
|
||||||
cat >&2 <<EOF
|
cat >&2 <<EOF
|
||||||
Usage: omz changelog [version]
|
Usage: ${(j: :)${(s.::.)0#_}} [version]
|
||||||
|
|
||||||
NOTE: <version> must be a valid branch, tag or commit.
|
NOTE: <version> must be a valid branch, tag or commit.
|
||||||
EOF
|
EOF
|
||||||
|
@ -193,9 +193,9 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
function _omz::plugin {
|
function _omz::plugin {
|
||||||
(( $# > 0 && $+functions[_omz::plugin::$1] )) || {
|
(( $# > 0 && $+functions[$0::$1] )) || {
|
||||||
cat >&2 <<EOF
|
cat >&2 <<EOF
|
||||||
Usage: omz plugin <command> [options]
|
Usage: ${(j: :)${(s.::.)0#_}} <command> [options]
|
||||||
|
|
||||||
Available commands:
|
Available commands:
|
||||||
|
|
||||||
|
@ -212,12 +212,12 @@ EOF
|
||||||
local command="$1"
|
local command="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
_omz::plugin::$command "$@"
|
$0::$command "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
function _omz::plugin::disable {
|
function _omz::plugin::disable {
|
||||||
if [[ -z "$1" ]]; then
|
if [[ -z "$1" ]]; then
|
||||||
echo >&2 "Usage: omz plugin disable <plugin> [...]"
|
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin> [...]"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -307,7 +307,7 @@ multi == 1 && length(\$0) > 0 {
|
||||||
|
|
||||||
function _omz::plugin::enable {
|
function _omz::plugin::enable {
|
||||||
if [[ -z "$1" ]]; then
|
if [[ -z "$1" ]]; then
|
||||||
echo >&2 "Usage: omz plugin enable <plugin> [...]"
|
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin> [...]"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -383,7 +383,7 @@ multi == 1 && /^[^#]*\)/ {
|
||||||
|
|
||||||
function _omz::plugin::info {
|
function _omz::plugin::info {
|
||||||
if [[ -z "$1" ]]; then
|
if [[ -z "$1" ]]; then
|
||||||
echo >&2 "Usage: omz plugin info <plugin>"
|
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin>"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -430,7 +430,7 @@ function _omz::plugin::list {
|
||||||
|
|
||||||
function _omz::plugin::load {
|
function _omz::plugin::load {
|
||||||
if [[ -z "$1" ]]; then
|
if [[ -z "$1" ]]; then
|
||||||
echo >&2 "Usage: omz plugin load <plugin> [...]"
|
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin> [...]"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -477,9 +477,9 @@ function _omz::plugin::load {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _omz::pr {
|
function _omz::pr {
|
||||||
(( $# > 0 && $+functions[_omz::pr::$1] )) || {
|
(( $# > 0 && $+functions[$0::$1] )) || {
|
||||||
cat >&2 <<EOF
|
cat >&2 <<EOF
|
||||||
Usage: omz pr <command> [options]
|
Usage: ${(j: :)${(s.::.)0#_}} <command> [options]
|
||||||
|
|
||||||
Available commands:
|
Available commands:
|
||||||
|
|
||||||
|
@ -493,7 +493,7 @@ EOF
|
||||||
local command="$1"
|
local command="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
_omz::pr::$command "$@"
|
$0::$command "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
function _omz::pr::clean {
|
function _omz::pr::clean {
|
||||||
|
@ -534,7 +534,7 @@ function _omz::pr::test {
|
||||||
|
|
||||||
# Check the input
|
# Check the input
|
||||||
if ! [[ -n "$1" && "$1" =~ ^[[:digit:]]+$ ]]; then
|
if ! [[ -n "$1" && "$1" =~ ^[[:digit:]]+$ ]]; then
|
||||||
echo >&2 "Usage: omz pr test <PR_NUMBER_or_URL>"
|
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <PR_NUMBER_or_URL>"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -619,9 +619,9 @@ function _omz::reload {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _omz::theme {
|
function _omz::theme {
|
||||||
(( $# > 0 && $+functions[_omz::theme::$1] )) || {
|
(( $# > 0 && $+functions[$0::$1] )) || {
|
||||||
cat >&2 <<EOF
|
cat >&2 <<EOF
|
||||||
Usage: omz theme <command> [options]
|
Usage: ${(j: :)${(s.::.)0#_}} <command> [options]
|
||||||
|
|
||||||
Available commands:
|
Available commands:
|
||||||
|
|
||||||
|
@ -636,7 +636,7 @@ EOF
|
||||||
local command="$1"
|
local command="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
_omz::theme::$command "$@"
|
$0::$command "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
function _omz::theme::list {
|
function _omz::theme::list {
|
||||||
|
@ -671,7 +671,7 @@ function _omz::theme::list {
|
||||||
|
|
||||||
function _omz::theme::set {
|
function _omz::theme::set {
|
||||||
if [[ -z "$1" ]]; then
|
if [[ -z "$1" ]]; then
|
||||||
echo >&2 "Usage: omz theme set <theme>"
|
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <theme>"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -739,7 +739,7 @@ EOF
|
||||||
|
|
||||||
function _omz::theme::use {
|
function _omz::theme::use {
|
||||||
if [[ -z "$1" ]]; then
|
if [[ -z "$1" ]]; then
|
||||||
echo >&2 "Usage: omz theme use <theme>"
|
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <theme>"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -761,7 +761,7 @@ function _omz::theme::use {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _omz::update {
|
function _omz::update {
|
||||||
local last_commit=$(cd "$ZSH"; git rev-parse HEAD)
|
local last_commit=$(builtin cd -q "$ZSH"; git rev-parse HEAD)
|
||||||
|
|
||||||
# Run update script
|
# Run update script
|
||||||
if [[ "$1" != --unattended ]]; then
|
if [[ "$1" != --unattended ]]; then
|
||||||
|
@ -777,7 +777,7 @@ function _omz::update {
|
||||||
command rm -rf "$ZSH/log/update.lock"
|
command rm -rf "$ZSH/log/update.lock"
|
||||||
|
|
||||||
# Restart the zsh session if there were changes
|
# Restart the zsh session if there were changes
|
||||||
if [[ "$1" != --unattended && "$(cd "$ZSH"; git rev-parse HEAD)" != "$last_commit" ]]; then
|
if [[ "$1" != --unattended && "$(builtin cd -q "$ZSH"; git rev-parse HEAD)" != "$last_commit" ]]; then
|
||||||
# Old zsh versions don't have ZSH_ARGZERO
|
# Old zsh versions don't have ZSH_ARGZERO
|
||||||
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
||||||
# Check whether to run a login shell
|
# Check whether to run a login shell
|
||||||
|
@ -787,16 +787,17 @@ function _omz::update {
|
||||||
|
|
||||||
function _omz::version {
|
function _omz::version {
|
||||||
(
|
(
|
||||||
cd "$ZSH"
|
builtin cd -q "$ZSH"
|
||||||
|
|
||||||
# Get the version name:
|
# Get the version name:
|
||||||
# 1) try tag-like version
|
# 1) try tag-like version
|
||||||
# 2) try name-rev
|
# 2) try branch name
|
||||||
# 3) try branch name
|
# 3) try name-rev (tag~<rev> or branch~<rev>)
|
||||||
local version
|
local version
|
||||||
version=$(command git describe --tags HEAD 2>/dev/null) \
|
version=$(command git describe --tags HEAD 2>/dev/null) \
|
||||||
|
|| version=$(command git symbolic-ref --quiet --short HEAD 2>/dev/null) \
|
||||||
|| version=$(command git name-rev --no-undefined --name-only --exclude="remotes/*" HEAD 2>/dev/null) \
|
|| version=$(command git name-rev --no-undefined --name-only --exclude="remotes/*" HEAD 2>/dev/null) \
|
||||||
|| version=$(command git symbolic-ref --quiet --short HEAD 2>/dev/null)
|
|| version="<detached>"
|
||||||
|
|
||||||
# Get short hash for the current HEAD
|
# Get short hash for the current HEAD
|
||||||
local commit=$(command git rev-parse --short HEAD 2>/dev/null)
|
local commit=$(command git rev-parse --short HEAD 2>/dev/null)
|
||||||
|
|
|
@ -16,10 +16,10 @@ plugins=(... aws)
|
||||||
Run `asp` without arguments to clear the profile.
|
Run `asp` without arguments to clear the profile.
|
||||||
* `asp [<profile>] login`: If AWS SSO has been configured in your aws profile, it will run the `aws sso login` command following profile selection.
|
* `asp [<profile>] login`: If AWS SSO has been configured in your aws profile, it will run the `aws sso login` command following profile selection.
|
||||||
|
|
||||||
* `acp [<profile>]`: in addition to `asp` functionality, it actually changes the profile by
|
* `acp [<profile>] [<mfa_token>]`: in addition to `asp` functionality, it actually changes
|
||||||
assuming the role specified in the `<profile>` configuration. It supports MFA and sets
|
the profile by assuming the role specified in the `<profile>` configuration. It supports
|
||||||
`$AWS_ACCESS_KEY_ID`, `$AWS_SECRET_ACCESS_KEY` and `$AWS_SESSION_TOKEN`, if obtained. It
|
MFA and sets `$AWS_ACCESS_KEY_ID`, `$AWS_SECRET_ACCESS_KEY` and `$AWS_SESSION_TOKEN`, if
|
||||||
requires the roles to be configured as per the
|
obtained. It requires the roles to be configured as per the
|
||||||
[official guide](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-role.html).
|
[official guide](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-role.html).
|
||||||
Run `acp` without arguments to clear the profile.
|
Run `acp` without arguments to clear the profile.
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ function acp() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local profile="$1"
|
local profile="$1"
|
||||||
|
local mfa_token="$2"
|
||||||
|
|
||||||
# Get fallback credentials for if the aws command fails or no command is run
|
# Get fallback credentials for if the aws command fails or no command is run
|
||||||
local aws_access_key_id="$(aws configure get aws_access_key_id --profile $profile)"
|
local aws_access_key_id="$(aws configure get aws_access_key_id --profile $profile)"
|
||||||
|
@ -58,9 +59,10 @@ function acp() {
|
||||||
|
|
||||||
if [[ -n "$mfa_serial" ]]; then
|
if [[ -n "$mfa_serial" ]]; then
|
||||||
local -a mfa_opt
|
local -a mfa_opt
|
||||||
local mfa_token
|
if [[ -z "$mfa_token" ]]; then
|
||||||
echo -n "Please enter your MFA token for $mfa_serial: "
|
echo -n "Please enter your MFA token for $mfa_serial: "
|
||||||
read -r mfa_token
|
read -r mfa_token
|
||||||
|
fi
|
||||||
if [[ -z "$sess_duration" ]]; then
|
if [[ -z "$sess_duration" ]]; then
|
||||||
echo -n "Please enter the session duration in seconds (900-43200; default: 3600, which is the default maximum for a role): "
|
echo -n "Please enter the session duration in seconds (900-43200; default: 3600, which is the default maximum for a role): "
|
||||||
read -r sess_duration
|
read -r sess_duration
|
||||||
|
|
|
@ -23,12 +23,12 @@ source_env() {
|
||||||
touch "$ZSH_DOTENV_DISALLOWED_LIST"
|
touch "$ZSH_DOTENV_DISALLOWED_LIST"
|
||||||
|
|
||||||
# early return if disallowed
|
# early return if disallowed
|
||||||
if command grep -q "$dirpath" "$ZSH_DOTENV_DISALLOWED_LIST" &>/dev/null; then
|
if command grep -Fx -q "$dirpath" "$ZSH_DOTENV_DISALLOWED_LIST" &>/dev/null; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check if current directory's .env file is allowed or ask for confirmation
|
# check if current directory's .env file is allowed or ask for confirmation
|
||||||
if ! command grep -q "$dirpath" "$ZSH_DOTENV_ALLOWED_LIST" &>/dev/null; then
|
if ! command grep -Fx -q "$dirpath" "$ZSH_DOTENV_ALLOWED_LIST" &>/dev/null; then
|
||||||
# get cursor column and print new line before prompt if not at line beginning
|
# get cursor column and print new line before prompt if not at line beginning
|
||||||
local column
|
local column
|
||||||
echo -ne "\e[6n" > /dev/tty
|
echo -ne "\e[6n" > /dev/tty
|
||||||
|
|
9
plugins/fig/README.md
Normal file
9
plugins/fig/README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Fig plugin
|
||||||
|
|
||||||
|
This plugin sets up completion for [Fig](https://fig.io/).
|
||||||
|
|
||||||
|
To use it, add `fig` to the plugins array in your zshrc file:
|
||||||
|
|
||||||
|
```zsh
|
||||||
|
plugins=(... fig)
|
||||||
|
```
|
13
plugins/fig/fig.plugin.zsh
Normal file
13
plugins/fig/fig.plugin.zsh
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
if ! (( $+commands[fig] )); then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If the completion file doesn't exist yet, we need to autoload it and
|
||||||
|
# bind it to `fig`. Otherwise, compinit will have already done that
|
||||||
|
if [[ ! -f "$ZSH_CACHE_DIR/completions/_fig" ]]; then
|
||||||
|
autoload -Uz _fig
|
||||||
|
typeset -g -A _comps
|
||||||
|
_comps[fig]=_fig
|
||||||
|
fi
|
||||||
|
|
||||||
|
fig completion zsh >| "$ZSH_CACHE_DIR/completions/_fig" &|
|
|
@ -24,9 +24,7 @@ compdef _git _git_log_prettily=git-log
|
||||||
|
|
||||||
# Warn if the current branch is a WIP
|
# Warn if the current branch is a WIP
|
||||||
function work_in_progress() {
|
function work_in_progress() {
|
||||||
if $(git log -n 1 2>/dev/null | grep -q -c "\-\-wip\-\-"); then
|
command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!"
|
||||||
echo "WIP!!"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if main exists and use instead of master
|
# Check if main exists and use instead of master
|
||||||
|
|
|
@ -11,12 +11,12 @@ command rm -f "${ZSH_CACHE_DIR}/helm_completion"
|
||||||
command mkdir -p "$ZSH_CACHE_DIR/completions"
|
command mkdir -p "$ZSH_CACHE_DIR/completions"
|
||||||
(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
|
(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
|
||||||
|
|
||||||
# If the completion file doesn't exist yet, we need to autoload it and
|
# If the completion file does not exist, generate it and then source it
|
||||||
# bind it to `helm`. Otherwise, compinit will have already done that.
|
# Otherwise, source it and regenerate in the background
|
||||||
if [[ ! -f "$ZSH_CACHE_DIR/completions/_helm" ]]; then
|
if [[ ! -f "$ZSH_CACHE_DIR/completions/_helm" ]]; then
|
||||||
typeset -g -A _comps
|
helm completion zsh >| "$ZSH_CACHE_DIR/completions/_helm"
|
||||||
autoload -Uz _helm
|
source "$ZSH_CACHE_DIR/completions/_helm"
|
||||||
_comps[helm]=_helm
|
else
|
||||||
fi
|
source "$ZSH_CACHE_DIR/completions/_helm"
|
||||||
|
|
||||||
helm completion zsh >| "$ZSH_CACHE_DIR/completions/_helm" &|
|
helm completion zsh >| "$ZSH_CACHE_DIR/completions/_helm" &|
|
||||||
|
fi
|
||||||
|
|
|
@ -8,15 +8,15 @@ if (( $+commands[kubectl] )); then
|
||||||
command mkdir -p "$ZSH_CACHE_DIR/completions"
|
command mkdir -p "$ZSH_CACHE_DIR/completions"
|
||||||
(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
|
(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
|
||||||
|
|
||||||
# If the completion file doesn't exist yet, we need to autoload it and
|
# If the completion file does not exist, generate it and then source it
|
||||||
# bind it to `kubectl`. Otherwise, compinit will have already done that.
|
# Otherwise, source it and regenerate in the background
|
||||||
if [[ ! -f "$ZSH_CACHE_DIR/completions/_kubectl" ]]; then
|
if [[ ! -f "$ZSH_CACHE_DIR/completions/_kubectl" ]]; then
|
||||||
typeset -g -A _comps
|
kubectl completion zsh >| "$ZSH_CACHE_DIR/completions/_kubectl"
|
||||||
autoload -Uz _kubectl
|
source "$ZSH_CACHE_DIR/completions/_kubectl"
|
||||||
_comps[kubectl]=_kubectl
|
else
|
||||||
|
source "$ZSH_CACHE_DIR/completions/_kubectl"
|
||||||
|
kubectl completion zsh >| "$ZSH_CACHE_DIR/completions/_kubectl" &|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
kubectl completion zsh >! "$ZSH_CACHE_DIR/completions/_kubectl" &|
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# This command is used a LOT both below and in daily life
|
# This command is used a LOT both below and in daily life
|
||||||
|
|
|
@ -117,7 +117,7 @@ function listMavenCompletions {
|
||||||
done
|
done
|
||||||
|
|
||||||
# List modules
|
# List modules
|
||||||
modules=($(find **/pom.xml -type f | grep -v '/target/classes/META-INF/' | grep '/pom.xml' |sed 's|\(.*\)/pom\.xml|\1|'))
|
modules=($(print -l **/pom.xml(-.N:h) | grep -v '/target/classes/META-INF/'))
|
||||||
|
|
||||||
reply=(
|
reply=(
|
||||||
# common lifecycle
|
# common lifecycle
|
||||||
|
|
9
plugins/poetry/README.md
Normal file
9
plugins/poetry/README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Poetry Plugin
|
||||||
|
|
||||||
|
This plugin automatically installs [Poetry](https://python-poetry.org/)'s completions for you, and keeps them up to date as your Poetry version changes.
|
||||||
|
|
||||||
|
To use it, add `poetry` to the plugins array in your zshrc file:
|
||||||
|
|
||||||
|
```zsh
|
||||||
|
plugins=(... poetry)
|
||||||
|
```
|
14
plugins/poetry/poetry.plugin.zsh
Normal file
14
plugins/poetry/poetry.plugin.zsh
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# Return immediately if poetry is not found
|
||||||
|
if (( ! $+commands[poetry] )); then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If the completion file doesn't exist yet, we need to autoload it and
|
||||||
|
# bind it to `poetry`. Otherwise, compinit will have already done that.
|
||||||
|
if [[ ! -f "$ZSH_CACHE_DIR/completions/_poetry" ]]; then
|
||||||
|
typeset -g -A _comps
|
||||||
|
autoload -Uz _poetry
|
||||||
|
_comps[poetry]=_poetry
|
||||||
|
fi
|
||||||
|
|
||||||
|
poetry completions zsh >| "$ZSH_CACHE_DIR/completions/_poetry" &|
|
|
@ -27,5 +27,5 @@ fi
|
||||||
rustup completions zsh >| "$ZSH_CACHE_DIR/completions/_rustup" &|
|
rustup completions zsh >| "$ZSH_CACHE_DIR/completions/_rustup" &|
|
||||||
cat >| "$ZSH_CACHE_DIR/completions/_cargo" <<'EOF'
|
cat >| "$ZSH_CACHE_DIR/completions/_cargo" <<'EOF'
|
||||||
#compdef cargo
|
#compdef cargo
|
||||||
source $(rustc +${${(z)$(rustup default)}[1]} --print sysroot)/share/zsh/site-functions/_cargo
|
source "$(rustc +${${(z)$(rustup default)}[1]} --print sysroot)"/share/zsh/site-functions/_cargo
|
||||||
EOF
|
EOF
|
||||||
|
|
|
@ -24,6 +24,20 @@ By pressing the <kbd>esc</kbd> key twice, you will have the same command with `s
|
||||||
$ sudo apt-get install build-essential
|
$ sudo apt-get install build-essential
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The same happens for editing files with your default editor (defined in `$SUDO_EDITOR`, `$VISUAL` or `$EDITOR`, in that order):
|
||||||
|
|
||||||
|
If the editor defined were `vim`:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ vim /etc/hosts
|
||||||
|
```
|
||||||
|
|
||||||
|
By pressing the <kbd>esc</kbd> key twice, you will have the same command with `sudo -e` instead of the editor, that would open that editor with root privileges:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ sudo -e /etc/hosts
|
||||||
|
```
|
||||||
|
|
||||||
### Previous executed commands
|
### Previous executed commands
|
||||||
|
|
||||||
Say you want to delete a system file and denied:
|
Say you want to delete a system file and denied:
|
||||||
|
@ -44,6 +58,8 @@ Password:
|
||||||
$
|
$
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The same happens for file editing, as told before.
|
||||||
|
|
||||||
## Key binding
|
## Key binding
|
||||||
|
|
||||||
By default, the `sudo` plugin uses <kbd>Esc</kbd><kbd>Esc</kbd> as the trigger.
|
By default, the `sudo` plugin uses <kbd>Esc</kbd><kbd>Esc</kbd> as the trigger.
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# Description
|
# Description
|
||||||
# -----------
|
# -----------
|
||||||
#
|
#
|
||||||
# sudo or sudoedit will be inserted before the command
|
# sudo or sudo -e (replacement for sudoedit) will be inserted before the command
|
||||||
#
|
#
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Authors
|
# Authors
|
||||||
|
@ -11,14 +11,19 @@
|
||||||
# * Dongweiming <ciici123@gmail.com>
|
# * Dongweiming <ciici123@gmail.com>
|
||||||
# * Subhaditya Nath <github.com/subnut>
|
# * Subhaditya Nath <github.com/subnut>
|
||||||
# * Marc Cornellà <github.com/mcornella>
|
# * Marc Cornellà <github.com/mcornella>
|
||||||
|
# * Carlo Sala <carlosalag@protonmail.com>
|
||||||
#
|
#
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
__sudo-replace-buffer() {
|
__sudo-replace-buffer() {
|
||||||
local old=$1 new=$2 space=${2:+ }
|
local old=$1 new=$2 space=${2:+ }
|
||||||
if [[ ${#LBUFFER} -le ${#old} ]]; then
|
|
||||||
RBUFFER="${space}${BUFFER#$old }"
|
# if the cursor is positioned in the $old part of the text, make
|
||||||
LBUFFER="${new}"
|
# the substitution and leave the cursor after the $new text
|
||||||
|
if [[ $CURSOR -le ${#old} ]]; then
|
||||||
|
BUFFER="${new}${space}${BUFFER#$old }"
|
||||||
|
CURSOR=${#new}
|
||||||
|
# otherwise just replace $old with $new in the text before the cursor
|
||||||
else
|
else
|
||||||
LBUFFER="${new}${space}${LBUFFER#$old }"
|
LBUFFER="${new}${space}${LBUFFER#$old }"
|
||||||
fi
|
fi
|
||||||
|
@ -35,14 +40,21 @@ sudo-command-line() {
|
||||||
LBUFFER="${LBUFFER:1}"
|
LBUFFER="${LBUFFER:1}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
{
|
||||||
|
# If $SUDO_EDITOR or $VISUAL are defined, then use that as $EDITOR
|
||||||
|
# Else use the default $EDITOR
|
||||||
|
local EDITOR=${SUDO_EDITOR:-${VISUAL:-$EDITOR}}
|
||||||
|
|
||||||
# If $EDITOR is not set, just toggle the sudo prefix on and off
|
# If $EDITOR is not set, just toggle the sudo prefix on and off
|
||||||
if [[ -z "$EDITOR" ]]; then
|
if [[ -z "$EDITOR" ]]; then
|
||||||
case "$BUFFER" in
|
case "$BUFFER" in
|
||||||
sudoedit\ *) __sudo-replace-buffer "sudoedit" "" ;;
|
sudo\ -e\ *) __sudo-replace-buffer "sudo -e" "" ;;
|
||||||
sudo\ *) __sudo-replace-buffer "sudo" "" ;;
|
sudo\ *) __sudo-replace-buffer "sudo" "" ;;
|
||||||
*) LBUFFER="sudo $LBUFFER" ;;
|
*) LBUFFER="sudo $LBUFFER" ;;
|
||||||
esac
|
esac
|
||||||
else
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if the typed command is really an alias to $EDITOR
|
# Check if the typed command is really an alias to $EDITOR
|
||||||
|
|
||||||
# Get the first part of the typed command
|
# Get the first part of the typed command
|
||||||
|
@ -67,25 +79,26 @@ sudo-command-line() {
|
||||||
if [[ "$realcmd" = (\$EDITOR|$editorcmd|${editorcmd:c}) \
|
if [[ "$realcmd" = (\$EDITOR|$editorcmd|${editorcmd:c}) \
|
||||||
|| "${realcmd:c}" = ($editorcmd|${editorcmd:c}) ]] \
|
|| "${realcmd:c}" = ($editorcmd|${editorcmd:c}) ]] \
|
||||||
|| builtin which -a "$realcmd" | command grep -Fx -q "$editorcmd"; then
|
|| builtin which -a "$realcmd" | command grep -Fx -q "$editorcmd"; then
|
||||||
editorcmd="$cmd" # replace $editorcmd with the typed command so it matches below
|
__sudo-replace-buffer "$cmd" "sudo -e"
|
||||||
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for editor commands in the typed command and replace accordingly
|
# Check for editor commands in the typed command and replace accordingly
|
||||||
case "$BUFFER" in
|
case "$BUFFER" in
|
||||||
$editorcmd\ *) __sudo-replace-buffer "$editorcmd" "sudoedit" ;;
|
$editorcmd\ *) __sudo-replace-buffer "$editorcmd" "sudo -e" ;;
|
||||||
\$EDITOR\ *) __sudo-replace-buffer '$EDITOR' "sudoedit" ;;
|
\$EDITOR\ *) __sudo-replace-buffer '$EDITOR' "sudo -e" ;;
|
||||||
sudoedit\ *) __sudo-replace-buffer "sudoedit" "$EDITOR" ;;
|
sudo\ -e\ *) __sudo-replace-buffer "sudo -e" "$EDITOR" ;;
|
||||||
sudo\ *) __sudo-replace-buffer "sudo" "" ;;
|
sudo\ *) __sudo-replace-buffer "sudo" "" ;;
|
||||||
*) LBUFFER="sudo $LBUFFER" ;;
|
*) LBUFFER="sudo $LBUFFER" ;;
|
||||||
esac
|
esac
|
||||||
fi
|
} always {
|
||||||
|
|
||||||
# Preserve beginning space
|
# Preserve beginning space
|
||||||
LBUFFER="${WHITESPACE}${LBUFFER}"
|
LBUFFER="${WHITESPACE}${LBUFFER}"
|
||||||
|
|
||||||
# Redisplay edit buffer (compatibility with zsh-syntax-highlighting)
|
# Redisplay edit buffer (compatibility with zsh-syntax-highlighting)
|
||||||
zle redisplay
|
zle redisplay
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
zle -N sudo-command-line
|
zle -N sudo-command-line
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ svn_get_branch_name() {
|
||||||
}
|
}
|
||||||
|
|
||||||
svn_get_rev_nr() {
|
svn_get_rev_nr() {
|
||||||
sed -n 's/Revision:\ //p' "${1:-$(LANG= svn info 2>/dev/null)}"
|
sed -n 's/Revision:\ //p' <<<"${1:-$(LANG= svn info 2>/dev/null)}"
|
||||||
}
|
}
|
||||||
|
|
||||||
svn_dirty() {
|
svn_dirty() {
|
||||||
|
@ -67,10 +67,10 @@ svn_dirty_choose() {
|
||||||
root=$(sed -n 's/^Working Copy Root Path: //p' <<< "${1:-$(LANG= svn info 2>/dev/null)}")
|
root=$(sed -n 's/^Working Copy Root Path: //p' <<< "${1:-$(LANG= svn info 2>/dev/null)}")
|
||||||
if LANG= svn status "$root" 2>/dev/null | command grep -Eq '^\s*[ACDIM!?L]'; then
|
if LANG= svn status "$root" 2>/dev/null | command grep -Eq '^\s*[ACDIM!?L]'; then
|
||||||
# Grep exits with 0 when "One or more lines were selected", return "dirty".
|
# Grep exits with 0 when "One or more lines were selected", return "dirty".
|
||||||
echo $1
|
echo $2
|
||||||
else
|
else
|
||||||
# Otherwise, no lines were found, or an error occurred. Return clean.
|
# Otherwise, no lines were found, or an error occurred. Return clean.
|
||||||
echo $2
|
echo $3
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ The plugin also supports the following:
|
||||||
## Aliases
|
## Aliases
|
||||||
|
|
||||||
| Alias | Command | Description |
|
| Alias | Command | Description |
|
||||||
| ------ | -----------------------|---------------------------------------------------------- |
|
| ---------- | ---------------------- | -------------------------------------------------------- |
|
||||||
| `ta` | tmux attach -t | Attach new tmux session to already running named session |
|
| `ta` | tmux attach -t | Attach new tmux session to already running named session |
|
||||||
| `tad` | tmux attach -d -t | Detach named tmux session |
|
| `tad` | tmux attach -d -t | Detach named tmux session |
|
||||||
| `ts` | tmux new-session -s | Create a new named tmux session |
|
| `ts` | tmux new-session -s | Create a new named tmux session |
|
||||||
|
@ -24,11 +24,12 @@ The plugin also supports the following:
|
||||||
| `tksv` | tmux kill-server | Terminate all running tmux sessions |
|
| `tksv` | tmux kill-server | Terminate all running tmux sessions |
|
||||||
| `tkss` | tmux kill-session -t | Terminate named running tmux session |
|
| `tkss` | tmux kill-session -t | Terminate named running tmux session |
|
||||||
| `tmux` | `_zsh_tmux_plugin_run` | Start a new tmux session |
|
| `tmux` | `_zsh_tmux_plugin_run` | Start a new tmux session |
|
||||||
|
| `tmuxconf` | `$EDITOR ~/.tmux.conf` | Open .tmux.conf file with an editor |
|
||||||
|
|
||||||
## Configuration Variables
|
## Configuration Variables
|
||||||
|
|
||||||
| Variable | Description |
|
| Variable | Description |
|
||||||
|-------------------------------------|-------------------------------------------------------------------------------|
|
| ----------------------------------- | ----------------------------------------------------------------------------- |
|
||||||
| `ZSH_TMUX_AUTOSTART` | Automatically starts tmux (default: `false`) |
|
| `ZSH_TMUX_AUTOSTART` | Automatically starts tmux (default: `false`) |
|
||||||
| `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) |
|
| `ZSH_TMUX_AUTOSTART_ONCE` | Autostart only if tmux hasn't been started previously (default: `true`) |
|
||||||
| `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) |
|
| `ZSH_TMUX_AUTOCONNECT` | Automatically connect to a previous session if it exits (default: `true`) |
|
||||||
|
|
|
@ -11,6 +11,7 @@ alias ts='tmux new-session -s'
|
||||||
alias tl='tmux list-sessions'
|
alias tl='tmux list-sessions'
|
||||||
alias tksv='tmux kill-server'
|
alias tksv='tmux kill-server'
|
||||||
alias tkss='tmux kill-session -t'
|
alias tkss='tmux kill-session -t'
|
||||||
|
alias tmuxconf='$EDITOR ~/.tmux.conf'
|
||||||
|
|
||||||
# CONFIGURATION VARIABLES
|
# CONFIGURATION VARIABLES
|
||||||
# Automatically start tmux
|
# Automatically start tmux
|
||||||
|
|
|
@ -30,10 +30,10 @@ plugins=(... vi-mode)
|
||||||
```
|
```
|
||||||
|
|
||||||
- `MODE_INDICATOR`: controls the string displayed when the shell is in normal mode.
|
- `MODE_INDICATOR`: controls the string displayed when the shell is in normal mode.
|
||||||
See [Mode indicator](#mode-indicator) for details.
|
See [Mode indicators](#mode-indicators) for details.
|
||||||
|
|
||||||
- `INSERT_MODE_INDICATOR`: controls the string displayed when the shell is in insert mode.
|
- `INSERT_MODE_INDICATOR`: controls the string displayed when the shell is in insert mode.
|
||||||
See [Mode indicator](#mode-indicator) for details.
|
See [Mode indicators](#mode-indicators) for details.
|
||||||
|
|
||||||
## Mode indicators
|
## Mode indicators
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ _yarn_commands_scripts() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n $packageJson ]]; then
|
if [[ -n $packageJson ]]; then
|
||||||
scripts=($(cat "$packageJson" | perl -0777 -MJSON::PP -n -E '%r=decode_json($_); say for sort keys %{$r->{scripts}}'))
|
scripts=($(cat "$packageJson" | perl -0777 -MJSON::PP -n -E '$r=decode_json($_); do{($k=$_)=~s/:/\\:/g;say $k}for sort keys %{$r->{scripts}}'))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_describe 'command or script' _commands -- _global_commands -- scripts -- binaries
|
_describe 'command or script' _commands -- _global_commands -- scripts -- binaries
|
||||||
|
@ -144,7 +144,7 @@ _yarn_scripts() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n $packageJson ]]; then
|
if [[ -n $packageJson ]]; then
|
||||||
scripts=("${(@f)$(cat ${packageJson} | perl -0777 -MJSON::PP -n -E '%r=%{decode_json($_)->{scripts}}; printf "$_:$r{$_}\n" for sort keys %r')}")
|
scripts=("${(@f)$(cat ${packageJson} | perl -0777 -MJSON::PP -n -E '%r=%{decode_json($_)->{scripts}}; do{$k=$_;($e=$k)=~s/:/\\:/g; printf "$e:$r{$k}\n"} for sort keys %r')}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
commands=('env' $scripts $binaries)
|
commands=('env' $scripts $binaries)
|
||||||
|
|
|
@ -45,9 +45,7 @@ function rvm_gemset() {
|
||||||
function git_time_since_commit() {
|
function git_time_since_commit() {
|
||||||
if git rev-parse --git-dir > /dev/null 2>&1; then
|
if git rev-parse --git-dir > /dev/null 2>&1; then
|
||||||
# Only proceed if there is actually a commit.
|
# Only proceed if there is actually a commit.
|
||||||
if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
|
if last_commit=`git -c log.showSignature=false log --pretty=format:'%at' -1 2> /dev/null`; then
|
||||||
# Get the last commit.
|
|
||||||
last_commit=`git log --pretty=format:'%at' -1 2> /dev/null`
|
|
||||||
now=`date +%s`
|
now=`date +%s`
|
||||||
seconds_since_last_commit=$((now-last_commit))
|
seconds_since_last_commit=$((now-last_commit))
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ function _git_time_since_commit() {
|
||||||
local last_commit now seconds_since_last_commit
|
local last_commit now seconds_since_last_commit
|
||||||
local minutes hours days years commit_age
|
local minutes hours days years commit_age
|
||||||
# Only proceed if there is actually a commit.
|
# Only proceed if there is actually a commit.
|
||||||
if last_commit=$(git log --pretty=format:'%at' -1 2> /dev/null); then
|
if last_commit=$(command git -c log.showSignature=false log --format='%at' -1 2>/dev/null); then
|
||||||
now=$(date +%s)
|
now=$(date +%s)
|
||||||
seconds_since_last_commit=$((now-last_commit))
|
seconds_since_last_commit=$((now-last_commit))
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,7 @@ ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}"
|
||||||
function git_time_since_commit() {
|
function git_time_since_commit() {
|
||||||
if git rev-parse --git-dir > /dev/null 2>&1; then
|
if git rev-parse --git-dir > /dev/null 2>&1; then
|
||||||
# Only proceed if there is actually a commit.
|
# Only proceed if there is actually a commit.
|
||||||
if git log -n 1 > /dev/null 2>&1; then
|
if last_commit=`git -c log.showSignature=false log --pretty=format:'%at' -1 2> /dev/null`; then
|
||||||
# Get the last commit.
|
|
||||||
last_commit=`git log --pretty=format:'%at' -1 2> /dev/null`
|
|
||||||
now=`date +%s`
|
now=`date +%s`
|
||||||
seconds_since_last_commit=$((now-last_commit))
|
seconds_since_last_commit=$((now-last_commit))
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ function git_time_since_commit() {
|
||||||
local last_commit seconds_since_last_commit
|
local last_commit seconds_since_last_commit
|
||||||
|
|
||||||
# Only proceed if there is actually a commit
|
# Only proceed if there is actually a commit
|
||||||
if ! last_commit=$(command git log --pretty=format:'%at' -1 2>/dev/null); then
|
if ! last_commit=$(command git -c log.showSignature=false log --pretty=format:'%at' -1 2>/dev/null); then
|
||||||
echo "[$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL~%{$reset_color%}]"
|
echo "[$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL~%{$reset_color%}]"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -69,9 +69,7 @@ function rvm_gemset() {
|
||||||
function git_time_since_commit() {
|
function git_time_since_commit() {
|
||||||
if git rev-parse --git-dir > /dev/null 2>&1; then
|
if git rev-parse --git-dir > /dev/null 2>&1; then
|
||||||
# Only proceed if there is actually a commit.
|
# Only proceed if there is actually a commit.
|
||||||
if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
|
if last_commit=`git -c log.showSignature=false log --pretty=format:'%at' -1 2> /dev/null`; then
|
||||||
# Get the last commit.
|
|
||||||
last_commit=`git log --pretty=format:'%at' -1 2> /dev/null`
|
|
||||||
now=`date +%s`
|
now=`date +%s`
|
||||||
seconds_since_last_commit=$((now-last_commit))
|
seconds_since_last_commit=$((now-last_commit))
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,13 @@ ZSH_THEME_GIT_PROMPT_SUFFIX="$YS_VCS_PROMPT_SUFFIX"
|
||||||
ZSH_THEME_GIT_PROMPT_DIRTY="$YS_VCS_PROMPT_DIRTY"
|
ZSH_THEME_GIT_PROMPT_DIRTY="$YS_VCS_PROMPT_DIRTY"
|
||||||
ZSH_THEME_GIT_PROMPT_CLEAN="$YS_VCS_PROMPT_CLEAN"
|
ZSH_THEME_GIT_PROMPT_CLEAN="$YS_VCS_PROMPT_CLEAN"
|
||||||
|
|
||||||
|
# SVN info
|
||||||
|
local svn_info='$(svn_prompt_info)'
|
||||||
|
ZSH_THEME_SVN_PROMPT_PREFIX="${YS_VCS_PROMPT_PREFIX1}svn${YS_VCS_PROMPT_PREFIX2}"
|
||||||
|
ZSH_THEME_SVN_PROMPT_SUFFIX="$YS_VCS_PROMPT_SUFFIX"
|
||||||
|
ZSH_THEME_SVN_PROMPT_DIRTY="$YS_VCS_PROMPT_DIRTY"
|
||||||
|
ZSH_THEME_SVN_PROMPT_CLEAN="$YS_VCS_PROMPT_CLEAN"
|
||||||
|
|
||||||
# HG info
|
# HG info
|
||||||
local hg_info='$(ys_hg_prompt_info)'
|
local hg_info='$(ys_hg_prompt_info)'
|
||||||
ys_hg_prompt_info() {
|
ys_hg_prompt_info() {
|
||||||
|
@ -66,6 +73,7 @@ PROMPT="
|
||||||
%{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\
|
%{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\
|
||||||
${hg_info}\
|
${hg_info}\
|
||||||
${git_info}\
|
${git_info}\
|
||||||
|
${svn_info}\
|
||||||
${venv_info}\
|
${venv_info}\
|
||||||
\
|
\
|
||||||
[%*] $exit_code
|
[%*] $exit_code
|
||||||
|
|
|
@ -395,12 +395,12 @@ function main {
|
||||||
|
|
||||||
# Get the first version name:
|
# Get the first version name:
|
||||||
# 1) try tag-like version, or
|
# 1) try tag-like version, or
|
||||||
# 2) try name-rev, or
|
# 2) try branch name, or
|
||||||
# 3) try branch name, or
|
# 3) try name-rev, or
|
||||||
# 4) try short hash
|
# 4) try short hash
|
||||||
version=$(command git describe --tags $until 2>/dev/null) \
|
version=$(command git describe --tags $until 2>/dev/null) \
|
||||||
|| version=$(command git name-rev --no-undefined --name-only --exclude="remotes/*" $until 2>/dev/null) \
|
|
||||||
|| version=$(command git symbolic-ref --quiet --short $until 2>/dev/null) \
|
|| version=$(command git symbolic-ref --quiet --short $until 2>/dev/null) \
|
||||||
|
|| version=$(command git name-rev --no-undefined --name-only --exclude="remotes/*" $until 2>/dev/null) \
|
||||||
|| version=$(command git rev-parse --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
|
# Get commit list from $until commit until $since commit, or until root commit if $since is unset
|
||||||
|
@ -414,7 +414,7 @@ function main {
|
||||||
# --first-parent: commits from merged branches are omitted
|
# --first-parent: commits from merged branches are omitted
|
||||||
local SEP="0mZmAgIcSeP"
|
local SEP="0mZmAgIcSeP"
|
||||||
local -a raw_commits
|
local -a raw_commits
|
||||||
raw_commits=(${(0)"$(command git log -z \
|
raw_commits=(${(0)"$(command git -c log.showSignature=false log -z \
|
||||||
--format="%h${SEP}%D${SEP}%s${SEP}%b" --abbrev=7 \
|
--format="%h${SEP}%D${SEP}%s${SEP}%b" --abbrev=7 \
|
||||||
--no-merges --first-parent $range)"})
|
--no-merges --first-parent $range)"})
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,13 @@ fi
|
||||||
# - auto: the update is performed automatically when it's time
|
# - auto: the update is performed automatically when it's time
|
||||||
# - reminder: a reminder is shown to the user when it's time to update
|
# - reminder: a reminder is shown to the user when it's time to update
|
||||||
# - disabled: automatic update is turned off
|
# - disabled: automatic update is turned off
|
||||||
zstyle -s ':omz:update' mode update_mode || update_mode=prompt
|
zstyle -s ':omz:update' mode update_mode || {
|
||||||
|
update_mode=prompt
|
||||||
|
|
||||||
# Support old-style settings
|
# If the mode zstyle setting is not set, support old-style settings
|
||||||
[[ "$DISABLE_UPDATE_PROMPT" != true ]] || update_mode=auto
|
[[ "$DISABLE_UPDATE_PROMPT" != true ]] || update_mode=auto
|
||||||
[[ "$DISABLE_AUTO_UPDATE" != true ]] || update_mode=disabled
|
[[ "$DISABLE_AUTO_UPDATE" != true ]] || update_mode=disabled
|
||||||
|
}
|
||||||
|
|
||||||
# Cancel update if:
|
# Cancel update if:
|
||||||
# - the automatic update is disabled.
|
# - the automatic update is disabled.
|
||||||
|
@ -34,11 +36,11 @@ function current_epoch() {
|
||||||
|
|
||||||
function is_update_available() {
|
function is_update_available() {
|
||||||
local branch
|
local branch
|
||||||
branch=${"$(cd "$ZSH"; git config --local oh-my-zsh.branch)":-master}
|
branch=${"$(cd -q "$ZSH"; git config --local oh-my-zsh.branch)":-master}
|
||||||
|
|
||||||
local remote remote_url remote_repo
|
local remote remote_url remote_repo
|
||||||
remote=${"$(cd "$ZSH"; git config --local oh-my-zsh.remote)":-origin}
|
remote=${"$(cd -q "$ZSH"; git config --local oh-my-zsh.remote)":-origin}
|
||||||
remote_url=$(cd "$ZSH"; git config remote.$remote.url)
|
remote_url=$(cd -q "$ZSH"; git config remote.$remote.url)
|
||||||
|
|
||||||
local repo
|
local repo
|
||||||
case "$remote_url" in
|
case "$remote_url" in
|
||||||
|
@ -56,7 +58,7 @@ function is_update_available() {
|
||||||
|
|
||||||
# Get local HEAD. If this fails assume there are updates
|
# Get local HEAD. If this fails assume there are updates
|
||||||
local local_head
|
local local_head
|
||||||
local_head=$(cd "$ZSH"; git rev-parse $branch 2>/dev/null) || return 0
|
local_head=$(cd -q "$ZSH"; git rev-parse $branch 2>/dev/null) || return 0
|
||||||
|
|
||||||
# Get remote HEAD. If no suitable command is found assume there are updates
|
# Get remote HEAD. If no suitable command is found assume there are updates
|
||||||
# On any other error, skip the update (connection may be down)
|
# On any other error, skip the update (connection may be down)
|
||||||
|
@ -134,7 +136,7 @@ function update_ohmyzsh() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Test if Oh My Zsh directory is a git repository
|
# Test if Oh My Zsh directory is a git repository
|
||||||
if ! (cd "$ZSH" && LANG= git rev-parse &>/dev/null); then
|
if ! (cd -q "$ZSH" && LANG= git rev-parse &>/dev/null); then
|
||||||
echo >&2 "[oh-my-zsh] Can't update: not a git repository."
|
echo >&2 "[oh-my-zsh] Can't update: not a git repository."
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
101
tools/install.sh
101
tools/install.sh
|
@ -56,6 +56,28 @@ command_exists() {
|
||||||
command -v "$@" >/dev/null 2>&1
|
command -v "$@" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user_can_sudo() {
|
||||||
|
# The following command has 3 parts:
|
||||||
|
#
|
||||||
|
# 1. Run `sudo` with `-v`. Does the following:
|
||||||
|
# • with privilege: asks for a password immediately.
|
||||||
|
# • without privilege: exits with error code 1 and prints the message:
|
||||||
|
# Sorry, user <username> may not run sudo on <hostname>
|
||||||
|
#
|
||||||
|
# 2. Pass `-n` to `sudo` to tell it to not ask for a password. If the
|
||||||
|
# password is not required, the command will finish with exit code 0.
|
||||||
|
# If one is required, sudo will exit with error code 1 and print the
|
||||||
|
# message:
|
||||||
|
# sudo: a password is required
|
||||||
|
#
|
||||||
|
# 3. Check for the words "may not run sudo" in the output to really tell
|
||||||
|
# whether the user has privileges or not. For that we have to make sure
|
||||||
|
# to run `sudo` in the default locale (with `LANG=`) so that the message
|
||||||
|
# stays consistent regardless of the user's locale.
|
||||||
|
#
|
||||||
|
LANG= sudo -n -v 2>&1 | grep -q "may not run sudo"
|
||||||
|
}
|
||||||
|
|
||||||
# The [ -t 1 ] check only works when the function is not called from
|
# The [ -t 1 ] check only works when the function is not called from
|
||||||
# a subshell (like in `$(...)` or `(...)`, so this hack redefines the
|
# a subshell (like in `$(...)` or `(...)`, so this hack redefines the
|
||||||
# function at the top level to always return false when stdout is not
|
# function at the top level to always return false when stdout is not
|
||||||
|
@ -127,6 +149,24 @@ supports_hyperlinks() {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Adapted from code and information by Anton Kochkov (@XVilka)
|
||||||
|
# Source: https://gist.github.com/XVilka/8346728
|
||||||
|
supports_truecolor() {
|
||||||
|
case "$COLORTERM" in
|
||||||
|
truecolor|24bit) return 0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case "$TERM" in
|
||||||
|
iterm |\
|
||||||
|
tmux-truecolor |\
|
||||||
|
linux-truecolor |\
|
||||||
|
xterm-truecolor |\
|
||||||
|
screen-truecolor) return 0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
fmt_link() {
|
fmt_link() {
|
||||||
# $1: text, $2: url, $3: fallback mode
|
# $1: text, $2: url, $3: fallback mode
|
||||||
if supports_hyperlinks; then
|
if supports_hyperlinks; then
|
||||||
|
@ -155,7 +195,28 @@ fmt_error() {
|
||||||
|
|
||||||
setup_color() {
|
setup_color() {
|
||||||
# Only use colors if connected to a terminal
|
# Only use colors if connected to a terminal
|
||||||
if is_tty; then
|
if ! is_tty; then
|
||||||
|
RAINBOW=""
|
||||||
|
RED=""
|
||||||
|
GREEN=""
|
||||||
|
YELLOW=""
|
||||||
|
BLUE=""
|
||||||
|
BOLD=""
|
||||||
|
RESET=""
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if supports_truecolor; then
|
||||||
|
RAINBOW="
|
||||||
|
$(printf '\033[38;2;255;0;0m')
|
||||||
|
$(printf '\033[38;2;255;97;0m')
|
||||||
|
$(printf '\033[38;2;247;255;0m')
|
||||||
|
$(printf '\033[38;2;0;255;30m')
|
||||||
|
$(printf '\033[38;2;77;0;255m')
|
||||||
|
$(printf '\033[38;2;168;0;255m')
|
||||||
|
$(printf '\033[38;2;245;0;172m')
|
||||||
|
"
|
||||||
|
else
|
||||||
RAINBOW="
|
RAINBOW="
|
||||||
$(printf '\033[38;5;196m')
|
$(printf '\033[38;5;196m')
|
||||||
$(printf '\033[38;5;202m')
|
$(printf '\033[38;5;202m')
|
||||||
|
@ -165,21 +226,14 @@ setup_color() {
|
||||||
$(printf '\033[38;5;093m')
|
$(printf '\033[38;5;093m')
|
||||||
$(printf '\033[38;5;163m')
|
$(printf '\033[38;5;163m')
|
||||||
"
|
"
|
||||||
|
fi
|
||||||
|
|
||||||
RED=$(printf '\033[31m')
|
RED=$(printf '\033[31m')
|
||||||
GREEN=$(printf '\033[32m')
|
GREEN=$(printf '\033[32m')
|
||||||
YELLOW=$(printf '\033[33m')
|
YELLOW=$(printf '\033[33m')
|
||||||
BLUE=$(printf '\033[34m')
|
BLUE=$(printf '\033[34m')
|
||||||
BOLD=$(printf '\033[1m')
|
BOLD=$(printf '\033[1m')
|
||||||
RESET=$(printf '\033[m')
|
RESET=$(printf '\033[0m')
|
||||||
else
|
|
||||||
RAINBOW=""
|
|
||||||
RED=""
|
|
||||||
GREEN=""
|
|
||||||
YELLOW=""
|
|
||||||
BLUE=""
|
|
||||||
BOLD=""
|
|
||||||
RESET=""
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_ohmyzsh() {
|
setup_ohmyzsh() {
|
||||||
|
@ -285,7 +339,7 @@ EOF
|
||||||
"$YELLOW" "$RESET"
|
"$YELLOW" "$RESET"
|
||||||
read -r opt
|
read -r opt
|
||||||
case $opt in
|
case $opt in
|
||||||
y*|Y*|"") echo "Changing the shell..." ;;
|
y*|Y*|"") ;;
|
||||||
n*|N*) echo "Shell change skipped."; return ;;
|
n*|N*) echo "Shell change skipped."; return ;;
|
||||||
*) echo "Invalid choice. Shell change skipped."; return ;;
|
*) echo "Invalid choice. Shell change skipped."; return ;;
|
||||||
esac
|
esac
|
||||||
|
@ -323,11 +377,28 @@ EOF
|
||||||
if [ -n "$SHELL" ]; then
|
if [ -n "$SHELL" ]; then
|
||||||
echo "$SHELL" > ~/.shell.pre-oh-my-zsh
|
echo "$SHELL" > ~/.shell.pre-oh-my-zsh
|
||||||
else
|
else
|
||||||
grep "^$USERNAME:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh
|
grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Actually change the default shell to zsh
|
echo "Changing your shell to $zsh..."
|
||||||
if ! chsh -s "$zsh"; then
|
|
||||||
|
# Check if user has sudo privileges to run `chsh` with or without `sudo`
|
||||||
|
#
|
||||||
|
# This allows the call to succeed without password on systems where the
|
||||||
|
# user does not have a password but does have sudo privileges, like in
|
||||||
|
# Google Cloud Shell.
|
||||||
|
#
|
||||||
|
# On systems that don't have a user with passwordless sudo, the user will
|
||||||
|
# be prompted for the password either way, so this shouldn't cause any issues.
|
||||||
|
#
|
||||||
|
if user_can_sudo; then
|
||||||
|
chsh -s "$zsh" "$USER" # run chsh normally
|
||||||
|
else
|
||||||
|
sudo -k chsh -s "$zsh" "$USER" # -k forces the password prompt
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if the shell change was successful
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
fmt_error "chsh command unsuccessful. Change your default shell manually."
|
fmt_error "chsh command unsuccessful. Change your default shell manually."
|
||||||
else
|
else
|
||||||
export SHELL="$zsh"
|
export SHELL="$zsh"
|
||||||
|
|
|
@ -86,6 +86,24 @@ supports_hyperlinks() {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Adapted from code and information by Anton Kochkov (@XVilka)
|
||||||
|
# Source: https://gist.github.com/XVilka/8346728
|
||||||
|
supports_truecolor() {
|
||||||
|
case "$COLORTERM" in
|
||||||
|
truecolor|24bit) return 0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case "$TERM" in
|
||||||
|
iterm |\
|
||||||
|
tmux-truecolor |\
|
||||||
|
linux-truecolor |\
|
||||||
|
xterm-truecolor |\
|
||||||
|
screen-truecolor) return 0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
fmt_link() {
|
fmt_link() {
|
||||||
# $1: text, $2: url, $3: fallback mode
|
# $1: text, $2: url, $3: fallback mode
|
||||||
if supports_hyperlinks; then
|
if supports_hyperlinks; then
|
||||||
|
@ -107,6 +125,17 @@ setopt typeset_silent
|
||||||
typeset -a RAINBOW
|
typeset -a RAINBOW
|
||||||
|
|
||||||
if is_tty; then
|
if is_tty; then
|
||||||
|
if supports_truecolor; then
|
||||||
|
RAINBOW=(
|
||||||
|
"$(printf '\033[38;2;255;0;0m')"
|
||||||
|
"$(printf '\033[38;2;255;97;0m')"
|
||||||
|
"$(printf '\033[38;2;247;255;0m')"
|
||||||
|
"$(printf '\033[38;2;0;255;30m')"
|
||||||
|
"$(printf '\033[38;2;77;0;255m')"
|
||||||
|
"$(printf '\033[38;2;168;0;255m')"
|
||||||
|
"$(printf '\033[38;2;245;0;172m')"
|
||||||
|
)
|
||||||
|
else
|
||||||
RAINBOW=(
|
RAINBOW=(
|
||||||
"$(printf '\033[38;5;196m')"
|
"$(printf '\033[38;5;196m')"
|
||||||
"$(printf '\033[38;5;202m')"
|
"$(printf '\033[38;5;202m')"
|
||||||
|
@ -116,6 +145,7 @@ if is_tty; then
|
||||||
"$(printf '\033[38;5;093m')"
|
"$(printf '\033[38;5;093m')"
|
||||||
"$(printf '\033[38;5;163m')"
|
"$(printf '\033[38;5;163m')"
|
||||||
)
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
RED=$(printf '\033[31m')
|
RED=$(printf '\033[31m')
|
||||||
GREEN=$(printf '\033[32m')
|
GREEN=$(printf '\033[32m')
|
||||||
|
@ -164,7 +194,7 @@ last_commit=$(git rev-parse "$branch")
|
||||||
|
|
||||||
# Update Oh My Zsh
|
# Update Oh My Zsh
|
||||||
printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh"
|
printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh"
|
||||||
if git pull --rebase --stat $remote $branch; then
|
if git pull --rebase $remote $branch; then
|
||||||
# Check if it was really updated or not
|
# Check if it was really updated or not
|
||||||
if [[ "$(git rev-parse HEAD)" = "$last_commit" ]]; then
|
if [[ "$(git rev-parse HEAD)" = "$last_commit" ]]; then
|
||||||
message="Oh My Zsh is already at the latest version."
|
message="Oh My Zsh is already at the latest version."
|
||||||
|
|
Loading…
Reference in a new issue