1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-10-16 11:40:46 +00:00

Compare commits

...

13 commits

Author SHA1 Message Date
Himprakash Deka
a022140b6c
Merge a4c3c67308 into 1514145a09 2024-09-21 00:07:43 +05:30
Carlo Sala
1514145a09
feat(nvm): add _omz_nvm_load function 2024-09-19 11:44:51 +02:00
Carlo Sala
99e2c31484
feat(git): add git_previous_branch function
Closes #12538
2024-09-18 21:05:45 +02:00
Francesco Cataldo
e52598a5cc
feat(web-search): add reddit (#12664) 2024-09-18 20:43:52 +02:00
rakeshgm
d91944d47e
feat(gnzh): add virtualenv prompt (#12666) 2024-09-18 20:42:18 +02:00
Tushar Mohod
865291cb7a
feat (terraform): add apply -auto-approve alias (#12658)
Closes #12591
2024-09-18 20:40:54 +02:00
Himprakash Deka
a4c3c67308
Merge branch 'ohmyzsh:master' into master 2024-07-06 16:20:06 +05:30
Himprakash Deka
d103253567
Merge branch 'ohmyzsh:master' into master 2022-06-28 13:41:38 +05:30
Himprakash Deka
e6f6948c92
Merge branch 'ohmyzsh:master' into master 2022-06-14 21:58:25 +05:30
Himprakash Deka
99261f7ae8
Merge branch 'ohmyzsh:master' into master 2022-06-03 20:49:46 +05:30
Himprakash Deka
d861230cd3
Fix variable naming 2022-05-29 19:49:41 +05:30
Himprakash Deka
53b216000c
Fixed function bad naming 2022-05-29 09:00:43 +05:30
HimDek
c2ef915921 Improved mercurial prompt 2022-05-29 08:28:15 +05:30
10 changed files with 120 additions and 68 deletions

View file

@ -162,6 +162,18 @@ function git_current_branch() {
echo ${ref#refs/heads/}
}
# Outputs the name of the previously checked out branch
# Usage example: git pull origin $(git_current_branch)
# rev-parse --symbolic-full-name @{-1} only prints if it is a branch
function git_previous_branch() {
local ref
ref=$(__git_prompt_git rev-parse --quiet --symbolic-full-name @{-1} 2> /dev/null)
local ret=$?
if [[ $ret != 0 ]] || [[ -z $ref ]]; then
return # no git repo or non-branch previous ref
fi
echo ${ref#refs/heads/}
}
# Gets the number of commits ahead from remote
function git_commits_ahead() {

View file

@ -52,10 +52,18 @@ plugins=(... mercurial)
You can also redefine additional vars used in the plugin (after Oh My Zsh is sourced):
```zsh
ZSH_THEME_HG_PROMPT_PREFIX="%{$fg_bold[magenta]%}hg:(%{$fg[red]%}"
ZSH_THEME_HG_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_HG_PROMPT_DIRTY="%{$fg[magenta]%}) %{$fg[yellow]%}✗%{$reset_color%}"
ZSH_THEME_HG_PROMPT_CLEAN="%{$fg[magenta]%})"
ZSH_THEME_HG_PROMPT_PREFIX="("
ZSH_THEME_HG_PROMPT_SUFFIX=")"
ZSH_THEME_HG_PROMPT_SEPARATOR="|"
ZSH_THEME_HG_PROMPT_BRANCH="%{$fg_bold[magenta]%}"
ZSH_THEME_HG_PROMPT_BEHIND="%{↓%G%}"
ZSH_THEME_HG_PROMPT_AHEAD="%{↑%G%}"
ZSH_THEME_HG_PROMPT_MODIFIED="%{$fg[red]%}%{●%G%}"
ZSH_THEME_HG_PROMPT_ADDED="%{$fg[blue]%}%{✚%G%}"
ZSH_THEME_HG_PROMPT_REMOVED="%{$fg[red]%}%{✖%G%}"
ZSH_THEME_HG_PROMPT_DELETED="%{$fg[red]%}%{🗑️%G%}"
ZSH_THEME_HG_PROMPT_UNKNOWN="%{$fg[cyan]%}%{…%G%}"
ZSH_THEME_HG_PROMPT_CLEAN="%{$fg_bold[green]%}%{✔%G%}"
```
### Display repo branch and directory status in prompt

View file

@ -73,46 +73,66 @@ function hg_get_bookmark_name() {
echo "$(<"$dir/.hg/bookmarks.current")"
}
function hg_prompt_info {
local dir branch dirty
if ! dir=$(hg_root); then
return
function update_hg_vars() {
if $(hg id >/dev/null 2>&1); then
local rev="$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')"
local branch="$(hg id -b 2>/dev/null)"
local hg_status=`hg st`
HG_REV_BRANCH="${rev:gs/%/%%}%{$FG[239]%}@%{$reset_color%}${branch:gs/%/%%}"
HG_UNKNOWN="$(echo $hg_status | grep "^\?" | wc -l)"
HG_MODIFIED="$(echo $hg_status | grep "^\M" | wc -l)"
HG_ADDED="$(echo $hg_status | grep "^\A" | wc -l)"
HG_REMOVED="$(echo $hg_status | grep "^\R" | wc -l)"
HG_DELETED="$(echo $hg_status | grep "^\!" | wc -l)"
HG_AHEAD="$(hg log -r "draft()" | grep "summary" | wc -l)"
# HG_BEHIND="$(hg incoming | grep "summary" | wc -l)"
fi
if [[ ! -f "$dir/.hg/branch" ]]; then
branch=default
else
branch="$(<"$dir/.hg/branch")"
fi
dirty="$(hg_dirty)"
echo "${ZSH_THEME_HG_PROMPT_PREFIX}${branch:gs/%/%%}${dirty}${ZSH_THEME_HG_PROMPT_SUFFIX}"
}
function hg_dirty {
# Do nothing if clean / dirty settings aren't defined
if [[ -z "$ZSH_THEME_HG_PROMPT_DIRTY" && -z "$ZSH_THEME_HG_PROMPT_CLEAN" ]]; then
return
fi
# Check if there are modifications
local hg_status
if [[ "$DISABLE_UNTRACKED_FILES_DIRTY" = true ]]; then
if ! hg_status="$(hg status -q 2>/dev/null)"; then
return
function hg_prompt_info() {
update_hg_vars
if $(hg id >/dev/null 2>&1); then
local hg_status="$ZSH_THEME_HG_PROMPT_PREFIX$ZSH_THEME_HG_PROMPT_BRANCH$HG_REV_BRANCH%{${reset_color}%}"
if [[ "$HG_BEHIND" -ne "0" ]]; then
hg_status="$hg_status$ZSH_THEME_HG_PROMPT_BEHIND$HG_BEHIND%{$reset_color%}"
fi
else
if ! hg_status="$(hg status 2>/dev/null)"; then
return
if [[ "$HG_AHEAD" -ne "0" ]]; then
hg_status="$hg_status$ZSH_THEME_HG_PROMPT_AHEAD$HG_AHEAD%{$reset_color%}"
fi
hg_status="$hg_status$ZSH_THEME_HG_PROMPT_SEPARATOR"
if [[ "$HG_MODIFIED" -ne "0" ]]; then
hg_status="$hg_status$ZSH_THEME_HG_PROMPT_MODIFIED$HG_MODIFIED%{$reset_color%}"
fi
if [[ "$HG_ADDED" -ne "0" ]]; then
hg_status="$hg_status$ZSH_THEME_HG_PROMPT_ADDED$HG_ADDED%{$reset_color%}"
fi
if [[ "$HG_REMOVED" -ne "0" ]]; then
hg_status="$hg_status$ZSH_THEME_HG_PROMPT_REMOVED$HG_REMOVED%{$reset_color%}"
fi
if [[ "$HG_DELETED" -ne "0" ]]; then
hg_status="$hg_status$ZSH_THEME_HG_PROMPT_DELETED$HG_DELETED%{$reset_color%}"
fi
if [[ "$HG_UNKNOWN" -ne "0" ]]; then
hg_status="$hg_status$ZSH_THEME_HG_PROMPT_UNKNOWN$HG_UNKNOWN%{$reset_color%}"
fi
if [[ "$HG_MODIFIED" -eq "0" && "$HG_ADDED" -eq "0" && "$HG_REMOVED" -eq "0" && "$HG_DELETED" -eq "0" && "$HG_UNKNOWN" -eq "0" ]]; then
hg_status="$hg_status$ZSH_THEME_HG_PROMPT_CLEAN"
fi
hg_status="$hg_status%{${reset_color}%}$ZSH_THEME_HG_PROMPT_SUFFIX"
echo "$hg_status"
fi
# grep exits with 0 when dirty
if command grep -Eq '^\s*[ACDIMR!?L].*$' <<< "$hg_status"; then
echo $ZSH_THEME_HG_PROMPT_DIRTY
return
fi
echo $ZSH_THEME_HG_PROMPT_CLEAN
}
# Default values for the appearance of the prompt.
ZSH_THEME_HG_PROMPT_PREFIX="("
ZSH_THEME_HG_PROMPT_SUFFIX=")"
ZSH_THEME_HG_PROMPT_SEPARATOR="|"
ZSH_THEME_HG_PROMPT_BRANCH="%{$fg_bold[magenta]%}"
ZSH_THEME_HG_PROMPT_BEHIND="%{↓%G%}"
ZSH_THEME_HG_PROMPT_AHEAD="%{↑%G%}"
ZSH_THEME_HG_PROMPT_MODIFIED="%{$fg[red]%}%{●%G%}"
ZSH_THEME_HG_PROMPT_ADDED="%{$fg[blue]%}%{✚%G%}"
ZSH_THEME_HG_PROMPT_REMOVED="%{$fg[red]%}%{✖%G%}"
ZSH_THEME_HG_PROMPT_DELETED="%{$fg[red]%}%{🗑️%G%}"
ZSH_THEME_HG_PROMPT_UNKNOWN="%{$fg[cyan]%}%{…%G%}"
ZSH_THEME_HG_PROMPT_CLEAN="%{$fg_bold[green]%}%{✔%G%}"

View file

@ -42,6 +42,8 @@ as you want:
zstyle ':omz:plugins:nvm' lazy-cmd eslint prettier typescript ...
```
There will be a function `_omz_nvm_load` available to load `nvm` without executing any other trigger command.
#### `.nvmrc` autoload
Note: _if used at the same time as `lazy`, `autoload` will start working only after nvm has been lazy-loaded_

View file

@ -20,7 +20,7 @@ if [[ -z "$NVM_DIR" ]] || [[ ! -f "$NVM_DIR/nvm.sh" ]]; then
return
fi
function _omz_load_nvm_completion {
function _omz_nvm_setup_completion {
local _nvm_completion
# Load nvm bash completion
for _nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do
@ -33,12 +33,12 @@ function _omz_load_nvm_completion {
break
fi
done
unfunction _omz_load_nvm_completion
unfunction _omz_nvm_setup_completion
}
function _omz_setup_autoload {
function _omz_nvm_setup_autoload {
if ! zstyle -t ':omz:plugins:nvm' autoload; then
unfunction _omz_setup_autoload
unfunction _omz_nvm_setup_autoload
return
fi
@ -68,13 +68,13 @@ function _omz_setup_autoload {
add-zsh-hook chpwd load-nvmrc
load-nvmrc
unfunction _omz_setup_autoload
unfunction _omz_nvm_setup_autoload
}
if zstyle -t ':omz:plugins:nvm' lazy; then
# Call nvm when first using nvm, node, npm, pnpm, yarn, corepack or other commands in lazy-cmd
zstyle -a ':omz:plugins:nvm' lazy-cmd nvm_lazy_cmd
nvm_lazy_cmd=(nvm node npm npx pnpm pnpx yarn corepack $nvm_lazy_cmd) # default values
nvm_lazy_cmd=(_omz_nvm_load nvm node npm npx pnpm pnpx yarn corepack $nvm_lazy_cmd) # default values
eval "
function $nvm_lazy_cmd {
for func in $nvm_lazy_cmd; do
@ -84,14 +84,16 @@ if zstyle -t ':omz:plugins:nvm' lazy; then
done
# Load nvm if it exists in \$NVM_DIR
[[ -f \"\$NVM_DIR/nvm.sh\" ]] && source \"\$NVM_DIR/nvm.sh\"
_omz_load_nvm_completion
_omz_setup_autoload
\"\$0\" \"\$@\"
_omz_nvm_setup_completion
_omz_nvm_setup_autoload
if [[ \"\$0\" != _omz_nvm_load ]]; then
\"\$0\" \"\$@\"
fi
}
"
unset nvm_lazy_cmd
else
source "$NVM_DIR/nvm.sh"
_omz_load_nvm_completion
_omz_setup_autoload
_omz_nvm_setup_completion
_omz_nvm_setup_autoload
fi

View file

@ -15,22 +15,23 @@ plugins=(... terraform)
## Aliases
| Alias | Command |
|--------|----------------------------|
| `tf` | `terraform` |
| `tfa` | `terraform apply` |
| `tfc` | `terraform console` |
| `tfd` | `terraform destroy` |
| `tff` | `terraform fmt` |
| `tffr` | `terraform fmt -recursive` |
| `tfi` | `terraform init` |
| `tfiu` | `terraform init -upgrade` |
| `tfo` | `terraform output` |
| `tfp` | `terraform plan` |
| `tfv` | `terraform validate` |
| `tfs` | `terraform state` |
| `tft` | `terraform test` |
| `tfsh` | `terraform show` |
| Alias | Command |
|---------|----------------------------------|
| `tf` | `terraform` |
| `tfa` | `terraform apply` |
| `tfaa` | `terraform apply -auto-approve` |
| `tfc` | `terraform console` |
| `tfd` | `terraform destroy` |
| `tff` | `terraform fmt` |
| `tffr` | `terraform fmt -recursive` |
| `tfi` | `terraform init` |
| `tfiu` | `terraform init -upgrade` |
| `tfo` | `terraform output` |
| `tfp` | `terraform plan` |
| `tfv` | `terraform validate` |
| `tfs` | `terraform state` |
| `tft` | `terraform test` |
| `tfsh` | `terraform show` |
## Prompt function

View file

@ -17,6 +17,7 @@ function tf_version_prompt_info() {
alias tf='terraform'
alias tfa='terraform apply'
alias tfaa='terraform apply -auto-approve'
alias tfc='terraform console'
alias tfd='terraform destroy'
alias tff='terraform fmt'

View file

@ -51,6 +51,7 @@ Available search contexts are:
| `packagist` | `https://packagist.org/?query=` |
| `gopkg` | `https://pkg.go.dev/search?m=package&q=` |
| `chatgpt` | `https://chatgpt.com/?q=` |
| `reddit` | `https://www.reddit.com/search/?q=` |
Also there are aliases for bang-searching DuckDuckGo:

View file

@ -32,6 +32,7 @@ function web_search() {
packagist "https://packagist.org/?query="
gopkg "https://pkg.go.dev/search?m=package&q="
chatgpt "https://chatgpt.com/?q="
reddit "https://www.reddit.com/search/?q="
)
# check whether the search engine is supported
@ -85,6 +86,7 @@ alias npmpkg='web_search npmpkg'
alias packagist='web_search packagist'
alias gopkg='web_search gopkg'
alias chatgpt='web_search chatgpt'
alias reddit='web_search reddit'
#add your own !bang searches here
alias wiki='web_search duckduckgo \!w'

View file

@ -30,8 +30,9 @@ local return_code="%(?..%F{red}%? ↵%f)"
local user_host="${PR_USER}%F{cyan}@${PR_HOST}"
local current_dir="%B%F{blue}%~%f%b"
local git_branch='$(git_prompt_info)'
local venv_prompt='$(virtualenv_prompt_info)'
PROMPT="╭─${user_host} ${current_dir} \$(ruby_prompt_info) ${git_branch}
PROMPT="╭─${venv_prompt}${user_host} ${current_dir} \$(ruby_prompt_info) ${git_branch}
╰─$PR_PROMPT "
RPROMPT="${return_code}"
@ -39,5 +40,7 @@ ZSH_THEME_GIT_PROMPT_PREFIX="%F{yellow}"
ZSH_THEME_GIT_PROMPT_SUFFIX=" %f"
ZSH_THEME_RUBY_PROMPT_PREFIX="%F{red}"
ZSH_THEME_RUBY_PROMPT_SUFFIX="%f"
ZSH_THEME_VIRTUALENV_PREFIX="%F{red}("
ZSH_THEME_VIRTUALENV_SUFFIX=")%f "
}