mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2026-09-21 18:46:06 +02:00
Compare commits
20
Commits
ee78d3aedd
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6421f8e104 | ||
|
|
0b50afdbfd | ||
|
|
157eb033f2 | ||
|
|
e7852049a5 | ||
|
|
7ce781ea37 | ||
|
|
def0f255c5 | ||
|
|
0ee67f0428 | ||
|
|
ec2901b7d0 | ||
|
|
1396cdd674 | ||
|
|
2ea948e05b | ||
|
|
6cd3a0baf6 | ||
|
|
fcf965912c | ||
|
|
c648271b6b | ||
|
|
53f663f3d8 | ||
|
|
e995678ca8 | ||
|
|
aea374f522 | ||
|
|
6553f90c45 | ||
|
|
9bf43f682c | ||
|
|
1b72d609b4 | ||
|
|
3258baa8b4 |
@@ -19,7 +19,7 @@ dependencies:
|
||||
plugins/history-substring-search:
|
||||
repo: zsh-users/zsh-history-substring-search
|
||||
branch: master
|
||||
version: 14c8d2e0ffaee98f2df9850b19944f32546fdea5
|
||||
version: a0bdb0d47dbaba31dba2db7af8c48a5d9c74049a
|
||||
precopy: |
|
||||
set -e
|
||||
rm -f zsh-history-substring-search.plugin.zsh
|
||||
|
||||
@@ -3,5 +3,5 @@ charset-normalizer==3.5.1
|
||||
idna==3.19
|
||||
PyYAML==6.0.3
|
||||
requests==2.34.2
|
||||
semver==3.0.4
|
||||
urllib3==2.7.0
|
||||
semver==3.1.0
|
||||
urllib3==2.8.0
|
||||
|
||||
@@ -738,6 +738,9 @@ function _omz::reload {
|
||||
|
||||
# Old zsh versions don't have ZSH_ARGZERO
|
||||
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
||||
# ZSH_ARGZERO is how zsh was invoked, not the path to it, so re-resolve
|
||||
# anything that is not absolute via $PATH at exec time (see #13919)
|
||||
[[ "${zsh#-}" != /* ]] && (( $+commands[zsh] )) && zsh="zsh"
|
||||
# Check whether to run a login shell
|
||||
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
||||
}
|
||||
@@ -919,6 +922,9 @@ function _omz::update {
|
||||
if [[ "$(builtin cd -q "$ZSH"; git rev-parse HEAD)" != "$last_commit" ]]; then
|
||||
# Old zsh versions don't have ZSH_ARGZERO
|
||||
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
||||
# ZSH_ARGZERO is how zsh was invoked, not the path to it, so re-resolve
|
||||
# anything that is not absolute via $PATH at exec time (see #13919)
|
||||
[[ "${zsh#-}" != /* ]] && (( $+commands[zsh] )) && zsh="zsh"
|
||||
# Check whether to run a login shell
|
||||
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
||||
fi
|
||||
|
||||
+21
-10
@@ -12,10 +12,16 @@ function __git_prompt_git() {
|
||||
}
|
||||
|
||||
function _omz_git_prompt_info() {
|
||||
# If we are on a folder not tracked by git, get out.
|
||||
# Otherwise, check for hide-info at global and local repository level
|
||||
if ! __git_prompt_git rev-parse --git-dir &> /dev/null \
|
||||
|| [[ "$(__git_prompt_git config --get oh-my-zsh.hide-info 2>/dev/null)" == 1 ]]; then
|
||||
# Get the git dir and the current branch name in one call. Outside a repo
|
||||
# there is no output. On a detached HEAD the branch is "HEAD". On an unborn
|
||||
# branch git exits non-zero after printing the git dir.
|
||||
local -a info
|
||||
info=("${(@f)$(__git_prompt_git rev-parse --git-dir --abbrev-ref HEAD 2> /dev/null)}")
|
||||
local unborn=$(( $? != 0 ))
|
||||
[[ -n "$info[1]" ]] || return 0
|
||||
|
||||
# Check for hide-info at global and local repository level
|
||||
if [[ "$(__git_prompt_git config --get oh-my-zsh.hide-info 2>/dev/null)" == 1 ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -23,11 +29,15 @@ function _omz_git_prompt_info() {
|
||||
# - the current branch name
|
||||
# - the tag name if we are on a tag
|
||||
# - the short SHA of the current commit
|
||||
local ref
|
||||
ref=$(__git_prompt_git symbolic-ref --short HEAD 2> /dev/null) \
|
||||
|| ref=$(__git_prompt_git describe --tags --exact-match HEAD 2> /dev/null) \
|
||||
|| ref=$(__git_prompt_git rev-parse --short HEAD 2> /dev/null) \
|
||||
|| return 0
|
||||
# a git dir path may contain newlines, so the branch is the last line
|
||||
local ref="$info[-1]"
|
||||
if (( unborn )); then
|
||||
ref=$(__git_prompt_git symbolic-ref --short HEAD 2> /dev/null) || return 0
|
||||
elif [[ "$ref" == HEAD ]]; then
|
||||
ref=$(__git_prompt_git describe --tags --exact-match HEAD 2> /dev/null) \
|
||||
|| ref=$(__git_prompt_git rev-parse --short HEAD 2> /dev/null) \
|
||||
|| return 0
|
||||
fi
|
||||
|
||||
# Use global ZSH_THEME_GIT_SHOW_UPSTREAM=1 for including upstream remote info
|
||||
local upstream
|
||||
@@ -244,7 +254,8 @@ function parse_git_dirty() {
|
||||
FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}"
|
||||
;;
|
||||
esac
|
||||
STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -n 1)
|
||||
# only non-emptiness matters, so keep one line instead of the whole list
|
||||
__git_prompt_git status ${FLAGS} 2> /dev/null | read -r STATUS
|
||||
fi
|
||||
if [[ -n $STATUS ]]; then
|
||||
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
||||
|
||||
+2
-1
@@ -22,7 +22,8 @@ function title {
|
||||
print -Pn "\e]1;${1:q}\a" # set tab name
|
||||
;;
|
||||
screen*|tmux*)
|
||||
print -Pn "\ek${1:q}\e\\" # set screen hardstatus
|
||||
print -Pn "\e]2;${2:q}\e\\" # set tmux pane title
|
||||
print -Pn "\ek${1:q}\e\\" # set screen hardstatus/tmux window name if `allow-rename` is on
|
||||
;;
|
||||
*)
|
||||
if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
|
||||
|
||||
@@ -13,69 +13,92 @@ ZSH_THEME_RUBY_PROMPT_PREFIX="("
|
||||
ZSH_THEME_RUBY_PROMPT_SUFFIX=")"
|
||||
|
||||
|
||||
# The command probes below fork a process each, and their result doesn't change
|
||||
# from one shell to the next, so they're cached for a day (like lib/grep.zsh).
|
||||
typeset -A __omz_probes
|
||||
__omz_probe_cache="$ZSH_CACHE_DIR/appearance-probes"
|
||||
__omz_probe_cached=("$__omz_probe_cache"(Nm-1))
|
||||
[[ -z "$__omz_probe_cached" ]] || source "$__omz_probe_cache"
|
||||
|
||||
function __omz_test_cmd_args {
|
||||
# Usage: __omz_test_cmd_args cmd args...
|
||||
# Runs `cmd args... /dev/null` and remembers whether it succeeded, so a
|
||||
# command needing two operands passes the first one itself:
|
||||
# e.g. __omz_test_cmd_args gls --color -> gls --color /dev/null
|
||||
# __omz_test_cmd_args diff --color /dev/null -> diff --color /dev/null /dev/null
|
||||
local key="$*"
|
||||
if (( ! ${+__omz_probes[$key]} )); then
|
||||
command "$@" /dev/null &>/dev/null
|
||||
__omz_probes[$key]=$?
|
||||
if [[ -w "$ZSH_CACHE_DIR" ]]; then
|
||||
print -r -- "__omz_probes=(" "${(@qqkv)__omz_probes}" ")" >| "$__omz_probe_cache"
|
||||
fi
|
||||
fi
|
||||
return $__omz_probes[$key]
|
||||
}
|
||||
|
||||
# Use diff --color if available
|
||||
if command diff --color /dev/null{,} &>/dev/null; then
|
||||
if __omz_test_cmd_args diff --color /dev/null; then
|
||||
function diff {
|
||||
command diff --color "$@"
|
||||
}
|
||||
fi
|
||||
|
||||
# Don't set ls coloring if disabled
|
||||
[[ "$DISABLE_LS_COLORS" != true ]] || return 0
|
||||
# Set up ls coloring. Done in a function so the early return below still
|
||||
# reaches the cleanup at the end of this file.
|
||||
() {
|
||||
# Don't set ls coloring if disabled
|
||||
[[ "$DISABLE_LS_COLORS" != true ]] || return 0
|
||||
|
||||
# Default coloring for BSD-based ls
|
||||
export LSCOLORS="Gxfxcxdxbxegedabagacad"
|
||||
# Default coloring for BSD-based ls
|
||||
export LSCOLORS="Gxfxcxdxbxegedabagacad"
|
||||
|
||||
# Default coloring for GNU-based ls
|
||||
if [[ -z "$LS_COLORS" ]]; then
|
||||
# Define LS_COLORS via dircolors if available. Otherwise, set a default
|
||||
# equivalent to LSCOLORS (generated via https://geoff.greer.fm/lscolors)
|
||||
if (( $+commands[dircolors] )); then
|
||||
[[ -f "$HOME/.dircolors" ]] \
|
||||
&& source <(dircolors -b "$HOME/.dircolors") \
|
||||
|| source <(dircolors -b)
|
||||
else
|
||||
export LS_COLORS="di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43"
|
||||
# Default coloring for GNU-based ls
|
||||
if [[ -z "$LS_COLORS" ]]; then
|
||||
# Define LS_COLORS via dircolors if available. Otherwise, set a default
|
||||
# equivalent to LSCOLORS (generated via https://geoff.greer.fm/lscolors)
|
||||
if (( $+commands[dircolors] )); then
|
||||
[[ -f "$HOME/.dircolors" ]] \
|
||||
&& source <(dircolors -b "$HOME/.dircolors") \
|
||||
|| source <(dircolors -b)
|
||||
else
|
||||
export LS_COLORS="di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
function test-ls-args {
|
||||
# Usage: test-ls-args cmd args...
|
||||
# e.g. test-ls-args gls --color
|
||||
command "$@" /dev/null &>/dev/null
|
||||
# Find the option for using colors in ls, depending on the version
|
||||
case "$OSTYPE" in
|
||||
netbsd*)
|
||||
# On NetBSD, test if `gls` (GNU ls) is installed (this one supports colors);
|
||||
# otherwise, leave ls as is, because NetBSD's ls doesn't support -G
|
||||
__omz_test_cmd_args gls --color && alias ls='gls --color=tty'
|
||||
;;
|
||||
openbsd*)
|
||||
# On OpenBSD, `gls` (ls from GNU coreutils) and `colorls` (ls from base,
|
||||
# with color and multibyte support) are available from ports.
|
||||
# `colorls` will be installed on purpose and can't be pulled in by installing
|
||||
# coreutils (which might be installed for ), so prefer it to `gls`.
|
||||
__omz_test_cmd_args gls --color && alias ls='gls --color=tty'
|
||||
__omz_test_cmd_args colorls -G && alias ls='colorls -G'
|
||||
;;
|
||||
(darwin|freebsd)*)
|
||||
# This alias works by default just using $LSCOLORS
|
||||
__omz_test_cmd_args ls -G && alias ls='ls -G'
|
||||
# Only use GNU ls if installed and there are user defaults for $LS_COLORS,
|
||||
# as the default coloring scheme is not very pretty
|
||||
zstyle -t ':omz:lib:theme-and-appearance' gnu-ls \
|
||||
&& __omz_test_cmd_args gls --color \
|
||||
&& alias ls='gls --color=tty'
|
||||
;;
|
||||
*)
|
||||
if __omz_test_cmd_args ls --color; then
|
||||
alias ls='ls --color=tty'
|
||||
elif __omz_test_cmd_args ls -G; then
|
||||
alias ls='ls -G'
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Find the option for using colors in ls, depending on the version
|
||||
case "$OSTYPE" in
|
||||
netbsd*)
|
||||
# On NetBSD, test if `gls` (GNU ls) is installed (this one supports colors);
|
||||
# otherwise, leave ls as is, because NetBSD's ls doesn't support -G
|
||||
test-ls-args gls --color && alias ls='gls --color=tty'
|
||||
;;
|
||||
openbsd*)
|
||||
# On OpenBSD, `gls` (ls from GNU coreutils) and `colorls` (ls from base,
|
||||
# with color and multibyte support) are available from ports.
|
||||
# `colorls` will be installed on purpose and can't be pulled in by installing
|
||||
# coreutils (which might be installed for ), so prefer it to `gls`.
|
||||
test-ls-args gls --color && alias ls='gls --color=tty'
|
||||
test-ls-args colorls -G && alias ls='colorls -G'
|
||||
;;
|
||||
(darwin|freebsd)*)
|
||||
# This alias works by default just using $LSCOLORS
|
||||
test-ls-args ls -G && alias ls='ls -G'
|
||||
# Only use GNU ls if installed and there are user defaults for $LS_COLORS,
|
||||
# as the default coloring scheme is not very pretty
|
||||
zstyle -t ':omz:lib:theme-and-appearance' gnu-ls \
|
||||
&& test-ls-args gls --color \
|
||||
&& alias ls='gls --color=tty'
|
||||
;;
|
||||
*)
|
||||
if test-ls-args ls --color; then
|
||||
alias ls='ls --color=tty'
|
||||
elif test-ls-args ls -G; then
|
||||
alias ls='ls -G'
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
unfunction test-ls-args
|
||||
unfunction __omz_test_cmd_args
|
||||
unset __omz_probes __omz_probe_cache __omz_probe_cached
|
||||
|
||||
+22
-1
@@ -100,7 +100,28 @@ done
|
||||
# Figure out the SHORT hostname
|
||||
if [[ "$OSTYPE" = darwin* ]]; then
|
||||
# macOS's $HOST changes with dhcp, etc. Use LocalHostName if possible.
|
||||
SHORT_HOST=$(scutil --get LocalHostName 2>/dev/null) || SHORT_HOST="${HOST/.*/}"
|
||||
# scutil costs a fork on every start, so remember its answer for a day
|
||||
# (like lib/grep.zsh) and re-check sooner if $HOST changes.
|
||||
__omz_host_cache="$ZSH_CACHE_DIR/localhostname"
|
||||
__omz_host_cached=("$__omz_host_cache"(Nm-1))
|
||||
__omz_host_key=
|
||||
SHORT_HOST=
|
||||
if [[ -n "$__omz_host_cached" ]]; then
|
||||
if ! { read -r __omz_host_key && read -r SHORT_HOST } < "$__omz_host_cache"; then
|
||||
__omz_host_key=
|
||||
SHORT_HOST=
|
||||
fi
|
||||
fi
|
||||
if [[ "$__omz_host_key" != "$HOST" || -z "$SHORT_HOST" ]]; then
|
||||
# only cache what scutil actually answered, so a transient failure
|
||||
# doesn't pin the fallback name for a day
|
||||
if SHORT_HOST=$(scutil --get LocalHostName 2>/dev/null) && [[ -n "$SHORT_HOST" ]]; then
|
||||
[[ ! -w "$ZSH_CACHE_DIR" ]] || print -rl -- "$HOST" "$SHORT_HOST" >| "$__omz_host_cache"
|
||||
else
|
||||
SHORT_HOST="${HOST/.*/}"
|
||||
fi
|
||||
fi
|
||||
unset __omz_host_cache __omz_host_cached __omz_host_key
|
||||
else
|
||||
SHORT_HOST="${HOST/.*/}"
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
# AppSignal CLI plugin
|
||||
|
||||
This plugin adds aliases, guard rails and completion for the
|
||||
[AppSignal CLI](https://docs.appsignal.com/cli).
|
||||
|
||||
To use it, add `appsignal-cli` to the plugins array in your zshrc file:
|
||||
|
||||
```zsh
|
||||
plugins=(... appsignal-cli)
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
[AppSignal CLI](https://docs.appsignal.com/cli) 2.1 or newer, installed and on
|
||||
your `PATH`. The plugin does nothing if it is not:
|
||||
|
||||
```zsh
|
||||
brew install appsignal/appsignal-cli/appsignal-cli
|
||||
# or
|
||||
curl -sSL https://github.com/appsignal/appsignal-cli/releases/latest/download/install.sh | sudo sh
|
||||
```
|
||||
|
||||
Most commands need `appsignal-cli auth login` first.
|
||||
|
||||
## Aliases
|
||||
|
||||
| Alias | Command | Description |
|
||||
| :------ | :----------------------------- | :--------------------------------- |
|
||||
| `asig` | `appsignal-cli` | The AppSignal CLI itself |
|
||||
| `aslog` | `appsignal-cli logs tail` | Stream log lines as they arrive |
|
||||
| `asinc` | `appsignal-cli incidents list` | List incidents for an application |
|
||||
|
||||
`aslog` and `asinc` complete like the commands they stand in for, so
|
||||
`aslog --<TAB>` offers the flags of `appsignal-cli logs tail`.
|
||||
|
||||
## Functions
|
||||
|
||||
| Function | Description |
|
||||
| :-------------- | :----------------------------------------------------------------- |
|
||||
| `appsignal-cli` | Wraps the CLI to confirm before irreversible commands. See Settings |
|
||||
|
||||
## Completion
|
||||
|
||||
Every command completes with a description of what it does, at every level, and
|
||||
so do their flags and allowed values: incident states and severities, sort
|
||||
orders, log severities, trigger fields and comparison operators, output formats
|
||||
and skill targets. `samples` and `sample` complete like `traces`, as they do in
|
||||
the CLI itself.
|
||||
|
||||
`--org` completes offline from the `org` key of your project's
|
||||
`.appsignal.toml` and of the global config.
|
||||
|
||||
The AppSignal CLI ships no completion generator of its own, so `_appsignal-cli`
|
||||
is written from its command definitions and kept in this repository. It targets
|
||||
AppSignal CLI 2.1.x.
|
||||
|
||||
## Settings
|
||||
|
||||
Set these with `zstyle` in your zshrc, before Oh My Zsh is sourced.
|
||||
|
||||
### Confirming destructive commands
|
||||
|
||||
```zsh
|
||||
zstyle ':omz:plugins:appsignal-cli' confirm-destructive no
|
||||
```
|
||||
|
||||
By default the plugin asks for confirmation before four operations that the CLI
|
||||
itself performs without a prompt:
|
||||
|
||||
- `appsignal-cli logs metrics delete`
|
||||
- `appsignal-cli logs triggers delete`
|
||||
- `appsignal-cli triggers archive`, which also closes the trigger's alerts and
|
||||
incidents
|
||||
- `appsignal-cli incidents update --state CLOSED` when it names more than one
|
||||
incident, since that flag accepts a comma-separated list
|
||||
|
||||
Nothing else is intercepted, and the prompt is skipped when stdin is not a
|
||||
terminal, so scripts, pipelines and CI are unaffected. Set the style to `no` to
|
||||
turn the prompt off entirely, or run `command appsignal-cli` for a single
|
||||
invocation.
|
||||
|
||||
### Completing applications
|
||||
|
||||
```zsh
|
||||
zstyle ':omz:plugins:appsignal-cli' dynamic-app-completion yes
|
||||
```
|
||||
|
||||
Off by default. When enabled, `--app`, `--app-id` and `--environment` are
|
||||
completed from `appsignal-cli apps list --output json`, showing each
|
||||
application's name and environment next to its ID instead of making you copy
|
||||
IDs by hand. It is opt-in because it runs the CLI and makes a network call when
|
||||
you press <kbd>Tab</kbd>, and because it needs you to be authenticated. Results
|
||||
are cached for five minutes.
|
||||
|
||||
### Disabling the aliases
|
||||
|
||||
This works for every Oh My Zsh plugin:
|
||||
|
||||
```zsh
|
||||
zstyle ':omz:plugins:appsignal-cli' aliases no
|
||||
```
|
||||
|
||||
## Caveats
|
||||
|
||||
- `appsignal-cli` and the AppSignal Ruby gem's `appsignal` command are different
|
||||
tools. The gem's command installs and diagnoses the agent inside your app;
|
||||
this one queries your data. The plugin deliberately leaves `appsignal` alone,
|
||||
so it keeps working in projects that use the gem.
|
||||
- `appsignal-cli` is a shell function here. Run `command appsignal-cli` to reach
|
||||
the binary directly.
|
||||
- Most commands need exactly one of `--app-id` or `--app`. `--environment` only
|
||||
narrows `--app`; it does nothing next to `--app-id`.
|
||||
- `appsignal-cli project init` writes `.appsignal.toml`, and `auth login` then
|
||||
stores OAuth tokens in it. Do not commit that file.
|
||||
- `incidents delete-note`, `auth logout` and the `--clear-*` flags of
|
||||
`logs metrics update` and `logs triggers update` are destructive too, but are
|
||||
not prompted for: each affects a single note, login or field.
|
||||
- `triggers create` and `triggers update` have their own `--format`, for the
|
||||
format of the metric value. Everywhere else `--format` is a synonym for
|
||||
`--output`.
|
||||
- The CLI sends usage telemetry by default. `APPSIGNAL_CLI_TELEMETRY=0` turns it
|
||||
off, and `APPSIGNAL_CLI_DEBUG=1` shows internal errors.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,108 @@
|
||||
# AppSignal CLI: completion, aliases and guard rails.
|
||||
# https://docs.appsignal.com/cli
|
||||
|
||||
if (( ! $+commands[appsignal-cli] )); then
|
||||
return
|
||||
fi
|
||||
|
||||
# Does this invocation need confirming? Sets REPLY to the reason.
|
||||
#
|
||||
# The command path is collected from the leading bare words. Only the global
|
||||
# flags may precede a subcommand, so the first other flag ends the path: that
|
||||
# way an option value such as `--app "My App"` is never mistaken for one.
|
||||
function _appsignal_cli_is_destructive() {
|
||||
zstyle -T ':omz:plugins:appsignal-cli' confirm-destructive || return 1
|
||||
|
||||
# Nobody to answer: CI and pipelines are unaffected.
|
||||
[[ -t 0 ]] || return 1
|
||||
|
||||
local -a args=("$@") path numbers
|
||||
local arg state=""
|
||||
integer i=1 n=$# path_done=0
|
||||
|
||||
while (( i <= n )); do
|
||||
arg="$args[i]"
|
||||
case "$arg" in
|
||||
--) break ;;
|
||||
--state=*) state="${arg#--state=}"; path_done=1 ;;
|
||||
--state) state="$args[i+1]"; (( i++ )); path_done=1 ;;
|
||||
--number=*) numbers+=(${(s:,:)${arg#--number=}}); path_done=1 ;;
|
||||
# --number takes one or more values, comma-separated or repeated.
|
||||
--number)
|
||||
path_done=1
|
||||
while (( i < n )) && [[ "$args[i+1]" != -* ]]; do
|
||||
(( i++ ))
|
||||
numbers+=(${(s:,:)args[i]})
|
||||
done
|
||||
;;
|
||||
# The output flag is global, so it can appear before the subcommand.
|
||||
-o|--output|--format) (( i++ )) ;;
|
||||
-o*|--output=*|--format=*) ;;
|
||||
-*) path_done=1 ;;
|
||||
*) (( path_done )) || path+=("$arg") ;;
|
||||
esac
|
||||
(( i++ ))
|
||||
done
|
||||
|
||||
case "${(j: :)path[1,3]}" in
|
||||
"logs metrics delete")
|
||||
REPLY="deleting a log-derived metric cannot be undone."
|
||||
return 0
|
||||
;;
|
||||
"logs triggers delete")
|
||||
REPLY="deleting a log-based trigger cannot be undone."
|
||||
return 0
|
||||
;;
|
||||
"triggers archive")
|
||||
REPLY="archiving a trigger also closes its alerts and incidents."
|
||||
return 0
|
||||
;;
|
||||
"incidents update")
|
||||
if [[ "${(U)state}" == CLOSED ]] && (( $#numbers > 1 )); then
|
||||
REPLY="this closes $#numbers incidents at once."
|
||||
return 0
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# Adds a confirmation prompt before irreversible operations. Everything else
|
||||
# passes straight through, so `logs tail` keeps streaming and pipes stay clean.
|
||||
function appsignal-cli() {
|
||||
local REPLY
|
||||
if _appsignal_cli_is_destructive "$@"; then
|
||||
print -u2 -- "appsignal-cli: $REPLY"
|
||||
if ! read -q "?Continue? [y/N] "; then
|
||||
print -u2 -- ""
|
||||
return 130
|
||||
fi
|
||||
print -u2 -- ""
|
||||
fi
|
||||
|
||||
command appsignal-cli "$@"
|
||||
}
|
||||
|
||||
# Complete the aliases like the commands they stand in for.
|
||||
if (( $+functions[compdef] )); then
|
||||
_aslog() {
|
||||
words=(appsignal-cli logs tail ${words[2,-1]})
|
||||
(( CURRENT += 2 ))
|
||||
_appsignal-cli
|
||||
}
|
||||
|
||||
_asinc() {
|
||||
words=(appsignal-cli incidents list ${words[2,-1]})
|
||||
(( CURRENT += 2 ))
|
||||
_appsignal-cli
|
||||
}
|
||||
|
||||
compdef _appsignal-cli asig
|
||||
compdef _aslog aslog
|
||||
compdef _asinc asinc
|
||||
fi
|
||||
|
||||
alias asig='appsignal-cli'
|
||||
alias aslog='appsignal-cli logs tail'
|
||||
alias asinc='appsignal-cli incidents list'
|
||||
@@ -103,6 +103,7 @@ plugins=(... git)
|
||||
| `glods` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short` |
|
||||
| `glol` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset'` |
|
||||
| `glola` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --all` |
|
||||
| `glolm` | `git log $(git_main_branch) --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset'` |
|
||||
| `glols` | `git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --stat` |
|
||||
| `glo` | `git log --oneline --decorate` |
|
||||
| `glog` | `git log --oneline --decorate --graph` |
|
||||
@@ -254,6 +255,7 @@ receive further support.
|
||||
| `git_current_user_name` | Returns the `user.name` config value (Lives in `lib/git.zsh`) |
|
||||
| `git_develop_branch` | Returns the name of the “development” branch: `dev`, `devel`, `development` if they exist, `develop` otherwise |
|
||||
| `git_main_branch` | Returns the name of the main branch: `main` if it exists, `master` otherwise |
|
||||
| `gbcopy` | Copies current branch name to clipboard |
|
||||
| `grename <old> <new>` | Renames branch `<old>` to `<new>`, including on the origin remote |
|
||||
| `gbda` | Deletes all merged branches |
|
||||
| `gbds` | Deletes all squash-merged branches (**Note: performance degrades with number of branches**) |
|
||||
|
||||
@@ -49,6 +49,16 @@ function git_main_branch() {
|
||||
return 1
|
||||
}
|
||||
|
||||
function gbcopy() {
|
||||
command git rev-parse --git-dir &>/dev/null || return
|
||||
|
||||
local branch
|
||||
branch="$(git_current_branch)" || return
|
||||
[[ -n "$branch" ]] || return 1
|
||||
|
||||
print -rn -- "$branch" | clipcopy
|
||||
}
|
||||
|
||||
function grename() {
|
||||
if [[ -z "$1" || -z "$2" ]]; then
|
||||
echo "Usage: $0 old_branch new_branch"
|
||||
@@ -239,6 +249,7 @@ alias glod='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgre
|
||||
alias glola='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --all'
|
||||
alias glols='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --stat'
|
||||
alias glol='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset"'
|
||||
alias glolm='git log $(git_main_branch) --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset"'
|
||||
alias glo='git log --oneline --decorate'
|
||||
alias glog='git log --oneline --decorate --graph'
|
||||
alias gloga='git log --oneline --decorate --graph --all'
|
||||
|
||||
+95
-11
@@ -81,6 +81,7 @@ _go() {
|
||||
'tool[run specified go tool]'
|
||||
'version[print Go version]'
|
||||
'vet[run go tool vet on packages]'
|
||||
'work[workspace maintenance]'
|
||||
)
|
||||
if (( CURRENT == 2 )); then
|
||||
# explain go commands
|
||||
@@ -88,19 +89,38 @@ _go() {
|
||||
return
|
||||
fi
|
||||
build_flags=(
|
||||
'-a[force reinstallation of packages that are already up to date]'
|
||||
'-C[change to dir before running the command]:directory:_path_files -/'
|
||||
'-a[force rebuilding of packages that are already up-to-date]'
|
||||
'-n[print the commands but do not run them]'
|
||||
'-p[number of parallel builds]:number'
|
||||
'-race[enable data race detection]'
|
||||
'-x[print the commands]'
|
||||
'-msan[enable interoperation with memory sanitizer]'
|
||||
'-asan[enable interoperation with address sanitizer]'
|
||||
'-cover[enable code coverage instrumentation]'
|
||||
'-covermode[set the mode for coverage analysis]:mode:(set count atomic)'
|
||||
'-coverpkg[apply coverage analysis to matching packages]:pattern'
|
||||
'-v[print the names of packages as they are compiled]'
|
||||
'-work[print temporary directory name and keep it]'
|
||||
'-ccflags[flags for 5c/6c/8c]:flags'
|
||||
'-gcflags[flags for 5g/6g/8g]:flags'
|
||||
'-ldflags[flags for 5l/6l/8l]:flags'
|
||||
'-gccgoflags[flags for gccgo]:flags'
|
||||
'-compiler[name of compiler to use]:name'
|
||||
'-installsuffix[suffix to add to package directory]:suffix'
|
||||
'-x[print the commands]'
|
||||
'-asmflags[arguments to pass on each go tool asm invocation]:flags'
|
||||
'-buildmode[build mode to use]:mode:(archive c-archive c-shared default shared exe pie plugin)'
|
||||
'-buildvcs[stamp binaries with version control information]:mode:(true false auto)'
|
||||
'-compiler[name of compiler to use]:name:(gccgo gc)'
|
||||
'-gccgoflags[arguments to pass on each gccgo compiler/linker invocation]:flags'
|
||||
'-gcflags[arguments to pass on each go tool compile invocation]:flags'
|
||||
'-installsuffix[suffix to use in the package installation directory]:suffix'
|
||||
'-json[emit build output in JSON suitable for automated processing]'
|
||||
'-ldflags[arguments to pass on each go tool link invocation]:flags'
|
||||
'-linkshared[build code that will be linked against shared libraries]'
|
||||
'-mod[module download mode to use]:mode:(readonly vendor mod)'
|
||||
'-modcacherw[leave newly-created directories in the module cache read-write]'
|
||||
'-modfile[read and write an alternate go.mod file]:file:_files -g "*.mod"'
|
||||
'-overlay[read a JSON config file that provides an overlay for build operations]:file:_files -g "*.json"'
|
||||
'-pgo[specify the file path of a profile for profile-guided optimization]:file:_files'
|
||||
'-pkgdir[install and load all packages from dir]:directory:_path_files -/'
|
||||
'-tags[list of build tags to consider satisfied]:tags'
|
||||
'-trimpath[remove all file system paths from the resulting executable]'
|
||||
'-toolexec[program to use to invoke toolchain programs]:command'
|
||||
)
|
||||
|
||||
case ${words[2]} in
|
||||
@@ -125,17 +145,20 @@ _go() {
|
||||
;;
|
||||
install)
|
||||
_arguments -s -w : ${build_flags[@]} \
|
||||
"-v[show package names]" \
|
||||
'*:importpaths:__go_packages'
|
||||
;;
|
||||
get)
|
||||
_arguments -s -w : \
|
||||
${build_flags[@]}
|
||||
${build_flags[@]} \
|
||||
"-t[consider modules needed to build tests of packages]" \
|
||||
"-u[update modules providing dependencies to newer minor or patch releases]" \
|
||||
"-u=[update modules providing dependencies to patch releases]:mode:(patch)" \
|
||||
"-tool[add a matching tool line to go.mod for each listed package]" \
|
||||
"*:importpaths:__go_packages"
|
||||
;;
|
||||
build)
|
||||
_arguments -s -w : \
|
||||
${build_flags[@]} \
|
||||
"-v[show package names]" \
|
||||
"-o[output file]:file:_files" \
|
||||
"*:args:{ _alternative ':importpaths:__go_packages' ':files:_path_files -g \"*.go\"' }"
|
||||
;;
|
||||
@@ -238,6 +261,60 @@ _go() {
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
work)
|
||||
local -a work_commands
|
||||
work_commands+=(
|
||||
'edit[edit go.work from tools or scripts]'
|
||||
'init[initialize workspace file]'
|
||||
'sync[sync workspace build list to modules]'
|
||||
'use[add modules to workspace file]'
|
||||
'vendor[make vendored copy of dependencies]'
|
||||
)
|
||||
|
||||
if (( CURRENT == 3 )); then
|
||||
_values 'go work commands' ${work_commands[@]} "help[display help]"
|
||||
return
|
||||
fi
|
||||
|
||||
case ${words[3]} in
|
||||
help)
|
||||
_values 'go work commands' ${work_commands[@]}
|
||||
;;
|
||||
edit)
|
||||
_arguments -s -w : \
|
||||
"-fmt[reformat the go.work file]" \
|
||||
"-godebug[=key=value add a godebug key=value line]:key=value" \
|
||||
"-dropgodebug[=key drop an existing godebug line]:key" \
|
||||
"-use[=path add a use directive]:directory:_path_files -/" \
|
||||
"-dropuse[=path drop a use directive]:directory:_path_files -/" \
|
||||
"-replace[=old{@v}=new{@v} add a replacement of the given module path and version pair]:name" \
|
||||
"-dropreplace[=old{@v} drop a replacement of the given module path and version pair]:name" \
|
||||
"-go[={version} set the expected Go language version]:number" \
|
||||
"-toolchain[=name set the Go toolchain to use]:name" \
|
||||
"-print[print the final go.work in its text format]" \
|
||||
"-json[print the final go.work file in JSON format]" \
|
||||
"1:go.work file:_files -g 'go.work'"
|
||||
;;
|
||||
init)
|
||||
_arguments -s -w : \
|
||||
"*:module directories:_path_files -/"
|
||||
;;
|
||||
sync)
|
||||
;;
|
||||
use)
|
||||
_arguments -s -w : \
|
||||
"-r[search recursively for modules in the argument directories]" \
|
||||
"*:module directories:_path_files -/"
|
||||
;;
|
||||
vendor)
|
||||
_arguments -s -w : \
|
||||
"-e[attempt to proceed despite errors encountered while loading packages]" \
|
||||
"-v[print the names of vendored modules and packages]" \
|
||||
"-o[create the vendor directory at the given path]:output directory:_path_files -/" \
|
||||
"*:flags"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
help)
|
||||
_values "${commands[@]}" \
|
||||
'environment[show Go environment variables available]' \
|
||||
@@ -247,6 +324,13 @@ _go() {
|
||||
'testflag[description of testing flags]' \
|
||||
'testfunc[description of testing functions]'
|
||||
;;
|
||||
version)
|
||||
_arguments -s -w : \
|
||||
"-m[print module version information]" \
|
||||
"-v[report unrecognized files]" \
|
||||
"-json[print module version information in JSON format]" \
|
||||
"*:file:_files"
|
||||
;;
|
||||
run)
|
||||
_arguments -s -w : \
|
||||
${build_flags[@]} \
|
||||
|
||||
@@ -20,7 +20,7 @@ Requirements
|
||||
Install
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
Using the [Homebrew](https://brew.sh) package manager:
|
||||
Using the [Homebrew]( https://brew.sh ) package manager:
|
||||
|
||||
brew install zsh-history-substring-search
|
||||
echo 'source $(brew --prefix)/share/zsh-history-substring-search/zsh-history-substring-search.zsh' >> ~/.zshrc
|
||||
@@ -51,7 +51,7 @@ Using [zplug](https://github.com/zplug/zplug):
|
||||
|
||||
1. Add this repo to `~/.zshrc`:
|
||||
|
||||
zplug "zsh-users/zsh-history-substring-search", as: plugin
|
||||
zplug "zsh-users/zsh-history-substring-search", as:plugin
|
||||
|
||||
Using [antigen](https://github.com/zsh-users/antigen):
|
||||
|
||||
@@ -75,7 +75,7 @@ Using [Zinit](https://github.com/zdharma-continuum/zinit):
|
||||
|
||||
1. Use the `Oh-my-zsh` Zinit snippet in `~/.zshrc`:
|
||||
|
||||
zinit snippet OMZ::plugins/git/git.plugin.zsh`
|
||||
zinit snippet OMZ::plugins/git/git.plugin.zsh
|
||||
|
||||
2. Load the plugin in `~/.zshrc`:
|
||||
|
||||
|
||||
@@ -295,8 +295,8 @@ _history-substring-search-begin() {
|
||||
fi
|
||||
|
||||
#
|
||||
# Escape and join query parts with wildcard character '*' as separator
|
||||
# `(j:CHAR:)` join array to string with CHAR as separator
|
||||
# Escape and join query parts with wildcard character '*' as seperator
|
||||
# `(j:CHAR:)` join array to string with CHAR as seperator
|
||||
#
|
||||
local search_pattern="${(j:*:)_history_substring_search_query_parts[@]//(#m)[\][()|\\*?#<>~^]/\\$MATCH}*"
|
||||
|
||||
|
||||
@@ -23,6 +23,16 @@ plugins=(... podman)
|
||||
| pirm | `podman image rm` | Remove one or more images |
|
||||
| pit | `podman image tag` | Add a name and tag to a particular image |
|
||||
| plo | `podman container logs` | Fetch the logs of a podman container |
|
||||
| pmif | `podman machine info` | Display machine host info |
|
||||
| pmit | `podman machine init` | Initialize a virtual machine |
|
||||
| pmis | `podman machine inspect` | Inspect an existing machine |
|
||||
| pml | `podman machine list` | List machines |
|
||||
| pmo | `podman machine os` | Manage a Podman virtual machine's OS |
|
||||
| pmrm | `podman machine rm` | Remove an existing machine |
|
||||
| pms | `podman machine set` | Set a virtual machine setting |
|
||||
| pmss | `podman machine ssh` | SSH into an existing machine |
|
||||
| pmst | `podman machine start` | Start an existing machine |
|
||||
| pmsp | `podman machine stop` | Stop an existing machine |
|
||||
| pnc | `podman network create` | Create a new network |
|
||||
| pncn | `podman network connect` | Connect a container to a network |
|
||||
| pndcn | `podman network disconnect` | Disconnect a container from a network |
|
||||
|
||||
@@ -26,6 +26,16 @@ alias pils='podman image ls'
|
||||
alias pipu='podman image push'
|
||||
alias pirm='podman image rm'
|
||||
alias pit='podman image tag'
|
||||
alias pmif='podman machine info'
|
||||
alias pmit='podman machine init'
|
||||
alias pmis='podman machine inspect'
|
||||
alias pml='podman machine list'
|
||||
alias pmo='podman machine os'
|
||||
alias pmrm='podman machine rm'
|
||||
alias pms='podman machine set'
|
||||
alias pmss='podman machine ssh'
|
||||
alias pmst='podman machine start'
|
||||
alias pmsp='podman machine stop'
|
||||
alias plo='podman container logs'
|
||||
alias pnc='podman network create'
|
||||
alias pncn='podman network connect'
|
||||
|
||||
@@ -34,6 +34,8 @@ if [[ "$TERM" == screen* ]]; then
|
||||
# tell GNU screen what the tab window title ($1) and the hardstatus($2) should be
|
||||
function screen_set()
|
||||
{
|
||||
[[ "${DISABLE_AUTO_TITLE:-}" != true ]] || return 0
|
||||
|
||||
# set the tab window title (%t) for screen
|
||||
print -nR $'\033k'$1$'\033'\\\
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
# Shopify CLI plugin
|
||||
|
||||
This plugin adds aliases, helper functions and completion for the
|
||||
[Shopify CLI](https://shopify.dev/docs/api/shopify-cli).
|
||||
|
||||
To use it, add `shopify` to the plugins array in your zshrc file:
|
||||
|
||||
```zsh
|
||||
plugins=(... shopify)
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
[Shopify CLI](https://shopify.dev/docs/api/shopify-cli) 4.0 or newer, installed
|
||||
and on your `PATH`. The plugin does nothing if it is not:
|
||||
|
||||
```zsh
|
||||
npm install -g @shopify/cli
|
||||
# or
|
||||
brew tap shopify/shopify && brew install shopify-cli
|
||||
```
|
||||
|
||||
## Aliases
|
||||
|
||||
| Alias | Command | Description |
|
||||
| :----- | :-------- | :--------------------- |
|
||||
| `shop` | `shopify` | The Shopify CLI itself |
|
||||
|
||||
## Functions
|
||||
|
||||
| Function | Description |
|
||||
| :------------- | :--------------------------------------------------------------------------------- |
|
||||
| `shopd` | Runs `theme dev`, `app dev` or `hydrogen dev`, whichever fits the current project |
|
||||
| `shopi` | Shows what the current project is connected to |
|
||||
| `shopify_here` | Prints the kind of Shopify project you are in and the commands worth running in it |
|
||||
| `shopify` | Wraps the CLI to confirm before irreversible commands. See Settings |
|
||||
|
||||
`shopd` and `shopi` work out which topic applies by looking at the project you
|
||||
are standing in, so you do not have to remember whether this directory is a
|
||||
theme, an app or a Hydrogen storefront. They complete like the command they
|
||||
stand in for, so in a theme `shopd --<TAB>` offers the flags of
|
||||
`shopify theme dev`.
|
||||
|
||||
## Completion
|
||||
|
||||
Every command completes with a description of what it does, at every level, and
|
||||
so do their flags, short forms and allowed values. `--environment` completes
|
||||
from the `[environments.*]` sections of your local `shopify.theme.toml` or
|
||||
`shopify.app.toml`.
|
||||
|
||||
The Shopify CLI ships no completion generator of its own, so `_shopify` is
|
||||
generated from `shopify commands --json` and kept in this repository. It targets
|
||||
Shopify CLI 4.x.
|
||||
|
||||
## Settings
|
||||
|
||||
Set these with `zstyle` in your zshrc, before Oh My Zsh is sourced.
|
||||
|
||||
### Confirming destructive commands
|
||||
|
||||
```zsh
|
||||
zstyle ':omz:plugins:shopify' confirm-destructive no
|
||||
```
|
||||
|
||||
By default the plugin asks for confirmation before three irreversible
|
||||
operations:
|
||||
|
||||
- `shopify theme push` with `--live`/`-l` or `--publish`/`-p`, which overwrites
|
||||
or publishes the live storefront
|
||||
- `shopify theme delete`, which the CLI's own help describes as impossible to
|
||||
undo
|
||||
- `shopify app deploy --allow-deletes`, which can permanently remove extensions
|
||||
|
||||
Nothing else is intercepted, and the prompt is skipped when the command already
|
||||
carries `--force`/`-f` or when stdin is not a terminal, so scripts, pipelines
|
||||
and CI are unaffected. Set the style to `no` to turn the prompt off entirely.
|
||||
|
||||
### Completing theme IDs
|
||||
|
||||
```zsh
|
||||
zstyle ':omz:plugins:shopify' dynamic-theme-completion yes
|
||||
```
|
||||
|
||||
Off by default. When enabled, `--theme` is completed from
|
||||
`shopify theme list --json`, showing each theme's name and role next to its ID
|
||||
instead of making you copy IDs by hand. It is opt-in because it runs the CLI and
|
||||
makes a network call when you press <kbd>Tab</kbd>, and because it needs you to
|
||||
be authenticated. Results are cached for five minutes.
|
||||
|
||||
### Disabling the aliases
|
||||
|
||||
This works for every Oh My Zsh plugin:
|
||||
|
||||
```zsh
|
||||
zstyle ':omz:plugins:shopify' aliases no
|
||||
```
|
||||
|
||||
## Caveats
|
||||
|
||||
- `shopify` is a shell function here. Run `command shopify` to reach the binary
|
||||
directly.
|
||||
- When a project has its own copy of the CLI in `node_modules/.bin/shopify`,
|
||||
that one is used in preference to the global install. App and Hydrogen
|
||||
projects normally pin the CLI in `package.json`, and running a different
|
||||
global version against them is a common source of confusing errors.
|
||||
- `--password` and `--store-password` are unrelated, and you often need both.
|
||||
`--password` is the CLI's own authentication token, from the Theme Access app
|
||||
or the Admin API. `--store-password` is the password for a
|
||||
password-protected storefront.
|
||||
- `shopify theme push` deletes remote files that are missing locally, and
|
||||
`shopify theme pull` deletes local files that are missing remotely, unless you
|
||||
pass `--nodelete`/`-n`. The plugin does not prompt for these.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,203 @@
|
||||
# Shopify CLI: completion, aliases and guard rails.
|
||||
# https://shopify.dev/docs/api/shopify-cli
|
||||
|
||||
if (( ! $+commands[shopify] )); then
|
||||
return
|
||||
fi
|
||||
|
||||
# Prefer a project-local CLI: app and Hydrogen projects pin their own version.
|
||||
# The walk stops at $HOME so a stray ~/node_modules cannot hijack every project.
|
||||
# $commands avoids resolving back to the wrapper function below.
|
||||
function _shopify_bin() {
|
||||
local dir="$PWD"
|
||||
while [[ -n "$dir" && "$dir" != "/" && "$dir" != "$HOME" ]]; do
|
||||
if [[ -x "$dir/node_modules/.bin/shopify" ]]; then
|
||||
print -r -- "$dir/node_modules/.bin/shopify"
|
||||
return 0
|
||||
fi
|
||||
dir="${dir:h}"
|
||||
done
|
||||
print -r -- "$commands[shopify]"
|
||||
}
|
||||
|
||||
# Print the project type in $PWD: hydrogen, app or theme.
|
||||
# Hydrogen is tested first because those projects usually carry a
|
||||
# shopify.app.toml too. shopify.theme.toml is not a theme marker: it only
|
||||
# exists once environments are configured.
|
||||
function _shopify_project_type() {
|
||||
local dir="$PWD"
|
||||
local -a app_config
|
||||
|
||||
while [[ -n "$dir" && "$dir" != "/" && "$dir" != "$HOME" ]]; do
|
||||
if [[ -x "$dir/node_modules/.bin/h2" ]] ||
|
||||
[[ -r "$dir/package.json" && "$(<"$dir/package.json")" == *'"@shopify/hydrogen"'* ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
app_config=("$dir"/shopify.app*.toml(N))
|
||||
if (( $#app_config )); then
|
||||
print -r -- app
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -f "$dir/config/settings_schema.json" && -f "$dir/layout/theme.liquid" ]]; then
|
||||
print -r -- theme
|
||||
return 0
|
||||
fi
|
||||
|
||||
dir="${dir:h}"
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# Does this invocation need confirming? Sets REPLY to the reason.
|
||||
function _shopify_is_destructive() {
|
||||
zstyle -T ':omz:plugins:shopify' confirm-destructive || return 1
|
||||
|
||||
# Nobody to answer: CI and pipelines are unaffected.
|
||||
[[ -t 0 ]] || return 1
|
||||
|
||||
local topic="$1" subcommand="$2" arg
|
||||
local -a long
|
||||
local short=""
|
||||
|
||||
# Short flags can be bundled, so collect them as characters: -al counts as l.
|
||||
for arg in "${@[3,-1]}"; do
|
||||
[[ "$arg" == "--" ]] && break
|
||||
case "$arg" in
|
||||
--*) long+=("${arg%%=*}") ;;
|
||||
-?*) short+="${${arg%%=*}#-}" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# An explicit force flag states the intent already.
|
||||
if (( long[(I)--force] )) || [[ "$short" == *f* ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
case "$topic $subcommand" in
|
||||
"theme push")
|
||||
if (( long[(I)--live] || long[(I)--publish] )) || [[ "$short" == *[lp]* ]]; then
|
||||
REPLY="this overwrites or publishes the live theme on the storefront."
|
||||
return 0
|
||||
fi
|
||||
;;
|
||||
"theme delete")
|
||||
REPLY="deleting a theme cannot be undone."
|
||||
return 0
|
||||
;;
|
||||
"app deploy")
|
||||
if (( long[(I)--allow-deletes] )); then
|
||||
REPLY="this can permanently remove app extensions."
|
||||
return 0
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# Adds a confirmation prompt before irreversible operations. Everything else
|
||||
# passes straight through, so `theme dev` stays interactive and pipes stay clean.
|
||||
function shopify() {
|
||||
local REPLY
|
||||
if _shopify_is_destructive "$@"; then
|
||||
print -u2 -- "shopify: $REPLY"
|
||||
if ! read -q "?Continue? [y/N] "; then
|
||||
print -u2 -- ""
|
||||
return 130
|
||||
fi
|
||||
print -u2 -- ""
|
||||
fi
|
||||
|
||||
"$(_shopify_bin)" "$@"
|
||||
}
|
||||
|
||||
# Print the commands worth running in the current directory.
|
||||
function shopify_here() {
|
||||
local project_type
|
||||
project_type="$(_shopify_project_type)"
|
||||
|
||||
case "$project_type" in
|
||||
theme)
|
||||
print -- "Shopify theme project."
|
||||
print -- " shopify theme dev Preview locally with live reload"
|
||||
print -- " shopify theme check Lint the theme"
|
||||
print -- " shopify theme list List the themes on the store"
|
||||
print -- " shopify theme pull Download a remote theme into this folder"
|
||||
print -- " shopify theme push Upload this folder to a remote theme"
|
||||
;;
|
||||
app)
|
||||
print -- "Shopify app project."
|
||||
print -- " shopify app dev Run the app against a development store"
|
||||
print -- " shopify app info Show how the app is configured"
|
||||
print -- " shopify app deploy Deploy the app and its extensions"
|
||||
print -- " shopify app logs Stream app logs"
|
||||
;;
|
||||
hydrogen)
|
||||
print -- "Hydrogen storefront."
|
||||
print -- " shopify hydrogen dev Run the storefront locally"
|
||||
print -- " shopify hydrogen build Build for production"
|
||||
print -- " shopify hydrogen deploy Deploy to Oxygen"
|
||||
print -- " shopify hydrogen link Link this project to a storefront"
|
||||
;;
|
||||
*)
|
||||
print -- "No Shopify project found here."
|
||||
print -- " shopify theme init Start a new theme"
|
||||
print -- " shopify app init Start a new app"
|
||||
print -- " shopify hydrogen init Start a new Hydrogen storefront"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Run the dev server for whichever kind of project this is.
|
||||
function shopd() {
|
||||
local project_type
|
||||
if ! project_type="$(_shopify_project_type)"; then
|
||||
print -u2 -- "shopd: not inside a Shopify theme, app or Hydrogen project."
|
||||
return 1
|
||||
fi
|
||||
shopify "$project_type" dev "$@"
|
||||
}
|
||||
|
||||
# Show what the current project is connected to.
|
||||
function shopi() {
|
||||
local project_type
|
||||
if ! project_type="$(_shopify_project_type)"; then
|
||||
print -u2 -- "shopi: not inside a Shopify theme, app or Hydrogen project."
|
||||
return 1
|
||||
fi
|
||||
case "$project_type" in
|
||||
hydrogen) shopify hydrogen list "$@" ;;
|
||||
*) shopify "$project_type" info "$@" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Complete the helpers like the commands they stand in for.
|
||||
if (( $+functions[compdef] )); then
|
||||
_shopd() {
|
||||
local project_type
|
||||
project_type="$(_shopify_project_type)" || return 1
|
||||
words=(shopify "$project_type" dev ${words[2,-1]})
|
||||
(( CURRENT += 2 ))
|
||||
_shopify
|
||||
}
|
||||
|
||||
_shopi() {
|
||||
local project_type
|
||||
project_type="$(_shopify_project_type)" || return 1
|
||||
if [[ "$project_type" == hydrogen ]]; then
|
||||
words=(shopify hydrogen list ${words[2,-1]})
|
||||
else
|
||||
words=(shopify "$project_type" info ${words[2,-1]})
|
||||
fi
|
||||
(( CURRENT += 2 ))
|
||||
_shopify
|
||||
}
|
||||
|
||||
compdef _shopd shopd
|
||||
compdef _shopi shopi
|
||||
fi
|
||||
|
||||
alias shop='shopify'
|
||||
@@ -19,6 +19,7 @@ plugins=(... systemadmin)
|
||||
| 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 -n 10` | Display the top 10 processes using the most memory |
|
||||
| pszombie| `ps -eo user,pid,ppid,state,comm \| awk '$4=="Z"'` | List zombie processes with ownership and parent process details |
|
||||
| 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 -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 |
|
||||
@@ -48,5 +49,4 @@ plugins=(... systemadmin)
|
||||
| d0 | Delete 0 byte files recursively in the current directory or another if specified |
|
||||
| geteip | Gather information regarding an external IP address using [icanhazip.com](https://icanhazip.com) |
|
||||
| getip | Determine the local IP Address with `ip addr` or `ifconfig` |
|
||||
| clrz | Clear zombie processes |
|
||||
| conssec | Show number of concurrent connections per second based on nginx/access.log file or another log file if specified |
|
||||
|
||||
@@ -28,6 +28,8 @@ 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 -n 10'
|
||||
# list all zombie processes with ownership and parent process details
|
||||
alias pszombie="ps -eo user,pid,ppid,state,comm | awk '\$4==\"Z\"'"
|
||||
# get top process eating cpu if not work try execute : 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 -n 10'
|
||||
@@ -177,11 +179,6 @@ function getip() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Clear zombie processes
|
||||
function clrz() {
|
||||
ps -eal | awk '{ if ($2 == "Z") {print $4}}' | kill -9
|
||||
}
|
||||
|
||||
# Second concurrent
|
||||
function conssec() {
|
||||
awk '{if($9~/200|30|404/)COUNT[$4]++}END{for( a in COUNT) print a,COUNT[a]}' "$(retlog)" | sort -k 2 -nr | head -n10
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# term_tab plugin
|
||||
|
||||
This plugin only works for Solaris and linux.
|
||||
This plugin works on Linux, macOS and Solaris.
|
||||
|
||||
term_tab - `cwd` for all open zsh sessions
|
||||
|
||||
|
||||
@@ -178,6 +178,11 @@ alias tmux=_zsh_tmux_plugin_run
|
||||
function _tmux_directory_session() {
|
||||
# current directory without leading path
|
||||
local dir=${PWD##*/}
|
||||
# tmux target syntax treats '.' and ':' as separators, a leading '$', '@' or '%'
|
||||
# as an id and a leading '=' as an exact-match prefix, so a session named after
|
||||
# such a directory can't be found on reattach
|
||||
dir=${dir//[.:]/_}
|
||||
dir=${dir/#[\$@%=]/_}
|
||||
# md5 hash for the full working directory path
|
||||
local md5=$(printf '%s' "$PWD" | md5sum | cut -d ' ' -f 1)
|
||||
# human friendly unique session name for this directory
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
PROMPT="${FG[117]}%~%{$reset_color%}\$(git_prompt_info)\$(virtualenv_prompt_info)${FG[133]}\$(git_prompt_status) ${FG[077]}ᐅ%{$reset_color%} "
|
||||
PROMPT="${FG[117]}%~%{$reset_color%}\$(git_prompt_info)\$(virtualenv_prompt_info)${FG[133]}\$(git_prompt_status) ${FG[077]}%(?..${FG[160]}[%?] )ᐅ%{$reset_color%} "
|
||||
|
||||
ZSH_THEME_GIT_PROMPT_PREFIX=" ${FG[012]}("
|
||||
ZSH_THEME_GIT_PROMPT_SUFFIX="${FG[012]})%{$reset_color%}"
|
||||
|
||||
@@ -185,7 +185,7 @@ function has_typed_input() {
|
||||
# Consider that no input can be typed if stty fails
|
||||
# (this might happen if stdin is not a terminal)
|
||||
local termios
|
||||
termios=$(stty --save 2>/dev/null) || return 1
|
||||
termios=$(stty -g 2>/dev/null) || return 1
|
||||
{
|
||||
# Disable canonical mode so that typed input counts
|
||||
# regardless of whether Enter was pressed
|
||||
|
||||
Reference in New Issue
Block a user