1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2026-01-16 23:37:55 +08:00

Compare commits

...

8 Commits

Author SHA1 Message Date
Léa Gris
95a06f3927
refactor(installer): fix static analysis warnings (#9529)
* refactor(install.sh): fix static analysis warnings

Clear all warnings and errors raised by shellcheck.net static analysis.

- Replace non-POSIX shell use of `$OSTYPE` by POSIX compliant check on `uname -o`.
- Move variables out of`printf` format string.
- Refactor/simplify string formatters for error and underline.
- Fix expansion of arguments to a single string `$*` rather than individual elements `$@` within the error and underline formatters.

* fix(uname): non-posix -o option

* fix(install.sh): non portable which

Replaced non-portable `which zsh` by portable `command -v zsh`
2021-03-16 00:06:06 +01:00
CrispyConductor
3f34ce4da4
fix(vi-mode): fix keymap indicator on zle-line-finish (#9620)
* Update VI_KEYMAP on zle-line-finish.  Fixes next prompt draw.

* Also fix vi-mode prompt redraw in case previous prompt was canceled

* Do not redraw fix prompt if VI_MODE_RESET_PROMPT_ON_MODE_CHANGE is unset

* Use a local variable instead of global in function
2021-03-15 23:32:49 +01:00
wahjava
e5d206c8c8
fix(fossil): PROMPT and RPROMPT are no longer exported (#9655)
Fixes #9654
2021-03-15 23:27:57 +01:00
Will Boyce
0e232d4853
feat(ssh-agent): add ssh-add-args setting (#7908)
* ssh-agent: add `:omz:plugins:ssh-agent ssh_add_args` option

* Clean up and document extra setting

* Document valid ssh-add arguments

Co-authored-by: Marc Cornellà <hello@mcornella.com>
2021-03-15 22:51:33 +01:00
Dario Vladović
90bdb8a156
feat(fzf): add support for Termux package (#9718) 2021-03-15 22:34:47 +01:00
Piotr Rogoża
9d556cd545
fix(emotty): fix bad assignment error (#9714) 2021-03-15 22:27:00 +01:00
John Delgado
040aadf7c4
feat(git): add grbo alias for git rebase --onto (#8088) 2021-03-15 20:06:01 +01:00
Marc Cornellà
e8716cb570
fix(uninstall): fix renaming .zshrc when no original rc file found
Fixes #9629
Fixes #9700
2021-03-15 19:51:31 +01:00
10 changed files with 72 additions and 29 deletions

View File

@ -29,7 +29,7 @@ function emotty() {
# Parse tty number via prompt expansion. %l equals:
# - N if tty = /dev/ttyN
# - pts/N if tty = /dev/pts/N
local tty = ${${(%):-%l}##pts/}
local tty=${${(%):-%l}##pts/}
# Normalize it to an emotty set index
(( tty = (tty % ${#${=emotty}}) + 1 ))

View File

@ -73,9 +73,9 @@ function _fossil_prompt () {
local is_prompt=`echo $PROMPT | grep git`
if [ "$is_prompt" = "" ]; then
export RPROMPT="$_rprompt"'$(fossil_prompt_info)'
RPROMPT="$_rprompt"'$(fossil_prompt_info)'
else
export PROMPT="$_prompt"'$(fossil_prompt_info) '
PROMPT="$_prompt"'$(fossil_prompt_info) '
fi
_FOSSIL_PROMPT="1"

View File

@ -64,11 +64,21 @@ function setup_using_debian_package() {
# NOTE: There is no need to configure PATH for debian package, all binaries
# are installed to /usr/bin by default
# Determine completion file path: first bullseye/sid, then buster/stretch
local completions="/usr/share/doc/fzf/examples/completion.zsh"
[[ -f "$completions" ]] || completions="/usr/share/zsh/vendor-completions/_fzf"
local completions key_bindings
local key_bindings="/usr/share/doc/fzf/examples/key-bindings.zsh"
case $PREFIX in
*com.termux*)
# Support Termux package
completions="${PREFIX}/share/fzf/completion.zsh"
key_bindings="${PREFIX}/share/fzf/key-bindings.zsh"
;;
*)
# Determine completion file path: first bullseye/sid, then buster/stretch
completions="/usr/share/doc/fzf/examples/completion.zsh"
[[ -f "$completions" ]] || completions="/usr/share/zsh/vendor-completions/_fzf"
key_bindings="/usr/share/doc/fzf/examples/key-bindings.zsh"
;;
esac
# Auto-completion
if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then

View File

@ -124,6 +124,7 @@ plugins=(... git)
| grbd | git rebase develop |
| grbi | git rebase -i |
| grbm | git rebase $(git_main_branch) |
| grbo | git rebase --onto |
| grbs | git rebase --skip |
| grev | git revert |
| grh | git reset |

View File

@ -224,6 +224,7 @@ alias grbc='git rebase --continue'
alias grbd='git rebase develop'
alias grbi='git rebase -i'
alias grbm='git rebase $(git_main_branch)'
alias grbo='git rebase --onto'
alias grbs='git rebase --skip'
alias grev='git revert'
alias grh='git reset'

View File

@ -9,7 +9,7 @@ To enable it, add `ssh-agent` to your plugins:
plugins=(... ssh-agent)
```
## Instructions
## Settings
**IMPORTANT: put these settings _before_ the line that sources oh-my-zsh**
@ -19,12 +19,16 @@ To enable **agent forwarding support** add the following to your zshrc file:
zstyle :omz:plugins:ssh-agent agent-forwarding on
```
----
To **load multiple identities** use the `identities` style, For example:
```zsh
zstyle :omz:plugins:ssh-agent identities id_rsa id_rsa2 id_github
```
----
To **set the maximum lifetime of the identities**, use the `lifetime` style.
The lifetime may be specified in seconds or as described in sshd_config(5)
(see _TIME FORMATS_). If left unspecified, the default lifetime is forever.
@ -33,6 +37,24 @@ The lifetime may be specified in seconds or as described in sshd_config(5)
zstyle :omz:plugins:ssh-agent lifetime 4h
```
----
To **pass arguments to the `ssh-add` command** that adds the identities on startup,
use the `ssh-add-args` setting. You can pass multiple arguments separated by spaces:
```zsh
zstyle :omz:plugins:ssh-agent ssh-add-args -K -c -a /run/user/1000/ssh-auth
```
These will then be passed the the `ssh-add` call as if written directly. The example
above will turn into:
```zsh
ssh-add -K -c -a /run/user/1000/ssh-auth <identities>
```
For valid `ssh-add` arguments run `ssh-add --help` or `man ssh-add`.
## Credits
Based on code from Joseph M. Reagle: https://www.cygwin.com/ml/cygwin/2001-06/msg00537.html

View File

@ -48,7 +48,9 @@ function _add_identities() {
fi
done
[[ -n "$not_loaded" ]] && ssh-add ${^not_loaded}
local args
zstyle -a :omz:plugins:ssh-agent ssh-add-args args
[[ -n "$not_loaded" ]] && ssh-add "${args[@]}" ${^not_loaded}
}
# Get the filename to store/lookup the environment from

View File

@ -50,13 +50,17 @@ zle -N zle-keymap-select
# These "echoti" statements were originally set in lib/key-bindings.zsh
# Not sure the best way to extend without overriding.
function zle-line-init() {
local prev_vi_keymap
prev_vi_keymap="${VI_KEYMAP:-}"
typeset -g VI_KEYMAP=main
[[ "$prev_vi_keymap" != 'main' ]] && [[ "${VI_MODE_RESET_PROMPT_ON_MODE_CHANGE:-}" = true ]] && zle reset-prompt
(( ! ${+terminfo[smkx]} )) || echoti smkx
_vi-mode-set-cursor-shape-for-keymap "${VI_KEYMAP}"
}
zle -N zle-line-init
function zle-line-finish() {
typeset -g VI_KEYMAP=main
(( ! ${+terminfo[rmkx]} )) || echoti rmkx
_vi-mode-set-cursor-shape-for-keymap default
}

View File

@ -57,15 +57,16 @@ command_exists() {
}
fmt_error() {
echo ${RED}"Error: $@"${RESET} >&2
printf '%sError: %s%s\n' "$BOLD$RED" "$*" "$RESET" >&2
}
fmt_underline() {
echo "$(printf '\033[4m')$@$(printf '\033[24m')"
printf '\033[4m%s\033[24m\n' "$*"
}
fmt_code() {
echo "\`$(printf '\033[38;5;247m')$@${RESET}\`"
# shellcheck disable=SC2016 # backtic in single-quote
printf '`\033[38;5;247m%s%s`\n' "$*" "$RESET"
}
setup_color() {
@ -102,7 +103,8 @@ setup_ohmyzsh() {
exit 1
}
if [ "$OSTYPE" = cygwin ] && git --version | grep -q msysgit; then
ostype=$(uname)
if [ -z "${ostype%CYGWIN*}" ] && git --version | grep -q msysgit; then
fmt_error "Windows/MSYS Git is not supported on Cygwin"
fmt_error "Make sure the Cygwin git package is installed and is first on the \$PATH"
exit 1
@ -130,7 +132,7 @@ setup_zshrc() {
OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
# Skip this if the user doesn't want to replace an existing .zshrc
if [ $KEEP_ZSHRC = yes ]; then
if [ "$KEEP_ZSHRC" = yes ]; then
echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Keeping...${RESET}"
return
fi
@ -162,7 +164,7 @@ export ZSH=\"$ZSH\"
setup_shell() {
# Skip setup if the user wants or stdin is closed (not running interactively).
if [ $CHSH = no ]; then
if [ "$CHSH" = no ]; then
return
fi
@ -183,8 +185,9 @@ EOF
echo "${BLUE}Time to change your default shell to zsh:${RESET}"
# Prompt for user choice on changing the default login shell
printf "${YELLOW}Do you want to change your default shell to zsh? [Y/n]${RESET} "
read opt
printf '%sDo you want to change your default shell to zsh? [Y/n]%s ' \
"$YELLOW" "$RESET"
read -r opt
case $opt in
y*|Y*|"") echo "Changing the shell..." ;;
n*|N*) echo "Shell change skipped."; return ;;
@ -211,7 +214,7 @@ EOF
# Get the path to the right zsh binary
# 1. Use the most preceding one based on $PATH, then check that it's in the shells file
# 2. If that fails, get a zsh path from the shells file, then check it actually exists
if ! zsh=$(which zsh) || ! grep -qx "$zsh" "$shells_file"; then
if ! zsh=$(command -v zsh) || ! grep -qx "$zsh" "$shells_file"; then
if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -1) || [ ! -f "$zsh" ]; then
fmt_error "no zsh binary found or not present in '$shells_file'"
fmt_error "change your default shell manually."
@ -222,7 +225,7 @@ EOF
# We're going to change the default shell, so back up the current one
if [ -n "$SHELL" ]; then
echo $SHELL > ~/.shell.pre-oh-my-zsh
echo "$SHELL" > ~/.shell.pre-oh-my-zsh
else
grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh
fi
@ -288,7 +291,7 @@ EOF
setup_zshrc
setup_shell
printf "$GREEN"
printf %s "$GREEN"
cat <<'EOF'
__ __
____ / /_ ____ ___ __ __ ____ _____/ /_
@ -307,7 +310,7 @@ Before you scream Oh My Zsh! please look over the ~/.zshrc file to select plugin
• Get stickers, shirts, coffee mugs and other swag: $(fmt_underline https://shop.planetargon.com/collections/oh-my-zsh)
EOF
printf "$RESET"
printf %s "$RESET"
if [ $RUNZSH = no ]; then
echo "${YELLOW}Run zsh to try it out.${RESET}"

View File

@ -9,20 +9,20 @@ if [ -d ~/.oh-my-zsh ]; then
rm -rf ~/.oh-my-zsh
fi
if [ -e ~/.zshrc ]; then
ZSHRC_SAVE=~/.zshrc.omz-uninstalled-$(date +%Y-%m-%d_%H-%M-%S)
echo "Found ~/.zshrc -- Renaming to ${ZSHRC_SAVE}"
mv ~/.zshrc "${ZSHRC_SAVE}"
fi
echo "Looking for original zsh config..."
ZSHRC_ORIG=~/.zshrc.pre-oh-my-zsh
if [ -e "$ZSHRC_ORIG" ]; then
echo "Found $ZSHRC_ORIG -- Restoring to ~/.zshrc"
if [ -e ~/.zshrc ]; then
ZSHRC_SAVE=~/.zshrc.omz-uninstalled-$(date +%Y-%m-%d_%H-%M-%S)
echo "Found ~/.zshrc -- Renaming to ${ZSHRC_SAVE}"
mv ~/.zshrc "${ZSHRC_SAVE}"
fi
mv "$ZSHRC_ORIG" ~/.zshrc
echo "Your original zsh config was restored."
else
echo "No original zsh config found"
fi
if hash chsh >/dev/null 2>&1 && [ -f ~/.shell.pre-oh-my-zsh ]; then