From bf57b4ff3d53726a1317459b0f48853e90d7a6e4 Mon Sep 17 00:00:00 2001 From: Joan Marcè i Igual Date: Fri, 20 Jan 2023 19:45:14 +0100 Subject: feat(functions/take): make `.tgz` behave as `.tar.gz` (#11446) --- lib/functions.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/functions.zsh b/lib/functions.zsh index dfcc4d961..6e1faa6aa 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -56,7 +56,7 @@ function takegit() { } function take() { - if [[ $1 =~ ^(https?|ftp).*\.tar\.(gz|bz2|xz)$ ]]; then + if [[ $1 =~ ^(https?|ftp).*\.(tar\.(gz|bz2|xz)|tgz)$ ]]; then takeurl "$1" elif [[ $1 =~ ^([A-Za-z0-9]\+@|https?|git|ssh|ftps?|rsync).*\.git/?$ ]]; then takegit "$1" -- cgit v1.2.3-70-g09d2 From 657ad0523d5a29e0bdc8af0cd63c23ac597406e8 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Wed, 25 Jan 2023 08:50:06 +0100 Subject: fix(theme-and-appearance): fix `diff` completion in macOS Closes #11416 Closes #11454 --- lib/theme-and-appearance.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index 00947f72d..9b908bef0 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -41,7 +41,11 @@ fi # enable diff color if possible. if command diff --color /dev/null /dev/null &>/dev/null; then - alias diff='diff --color' + function color-diff { + diff --color $@ + } + alias diff="color-diff" + compdef _diff color-diff # compdef is already loaded by this point fi setopt auto_cd -- cgit v1.2.3-70-g09d2 From ea4854dba3ef72e18df2c7cc79db2806d92322eb Mon Sep 17 00:00:00 2001 From: Hazael Sanchez Date: Thu, 2 Feb 2023 02:30:34 -0800 Subject: feat(directories): add config to skip aliases (#11469) Co-authored-by: Carlo Sala --- README.md | 10 ++++++++++ lib/directories.zsh | 2 ++ 2 files changed, 12 insertions(+) (limited to 'lib') diff --git a/README.md b/README.md index 1e4b7ff70..7f4a26cab 100644 --- a/README.md +++ b/README.md @@ -276,6 +276,16 @@ If you have many functions that go well together, you can put them as a `XYZ.plu If you would like to override the functionality of a plugin distributed with Oh My Zsh, create a plugin of the same name in the `custom/plugins/` directory and it will be loaded instead of the one in `plugins/`. +### Remove directories aliases + +If you want to skip ohmyzsh default +[directories aliases](https://github.com/ohmyzsh/ohmyzsh/blob/master/lib/directories.zsh) you can add the +following snippet to your `zshrc`, before loading `oh-my-zsh.sh` script: + +```zsh +zstyle ':omz:directories' aliases no +``` + ## Getting Updates By default, you will be prompted to check for updates every 2 weeks. You can choose other update modes by adding a line to your `~/.zshrc` file, **before Oh My Zsh is loaded**: diff --git a/lib/directories.zsh b/lib/directories.zsh index c62f56468..5aa1b3d5b 100644 --- a/lib/directories.zsh +++ b/lib/directories.zsh @@ -3,6 +3,8 @@ setopt auto_pushd setopt pushd_ignore_dups setopt pushdminus +zstyle -T ':omz:directories' aliases || return + alias -g ...='../..' alias -g ....='../../..' alias -g .....='../../../..' -- cgit v1.2.3-70-g09d2 From 379fe0fe131cff7a480f7975b32b0ea6fc7c2370 Mon Sep 17 00:00:00 2001 From: Julien Rottenberg Date: Tue, 7 Feb 2023 03:33:59 -0800 Subject: feat(azure): add `azure` plugin (#8848) Co-authored-by: hagridaaron Co-authored-by: Terry Closes #8847 --- lib/prompt_info_functions.zsh | 1 + plugins/azure/README.md | 49 ++++++++++++++++++++++++++++++++++ plugins/azure/azure.plugin.zsh | 60 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 plugins/azure/README.md create mode 100644 plugins/azure/azure.plugin.zsh (limited to 'lib') diff --git a/lib/prompt_info_functions.zsh b/lib/prompt_info_functions.zsh index e5535848b..3dc9b6d10 100644 --- a/lib/prompt_info_functions.zsh +++ b/lib/prompt_info_functions.zsh @@ -18,6 +18,7 @@ function chruby_prompt_info \ vi_mode_prompt_info \ virtualenv_prompt_info \ jenv_prompt_info \ + azure_prompt_info \ tf_prompt_info \ { return 1 diff --git a/plugins/azure/README.md b/plugins/azure/README.md new file mode 100644 index 000000000..f39930851 --- /dev/null +++ b/plugins/azure/README.md @@ -0,0 +1,49 @@ +# azure + +This plugin provides completion support for [azure cli](https://docs.microsoft.com/en-us/cli/azure/) +and a few utilities to manage azure subscriptions and display them in the prompt. + +To use it, add `azure` to the plugins array in your zshrc file. + +```zsh +plugins=(... azure) +``` + +## Plugin commands + + +* `az_subscriptions`: lists the available subscriptions in the `AZURE_CONFIG_DIR` (default: `~/.azure/`). + Used to provide completion for the `azss` function. + +* `azgs`: gets the current value of `$azure_subscription`. + +* `azss []`: sets the `$azure_subscription`. + + +NOTE : because azure keeps the state of active subscription in ${AZURE_CONFIG_DIR:-$HOME/.azure/azureProfile.json}, the prompt command requires `jq` to be enabled to parse the file. If jq is not in the path the prompt will show nothing + +## Theme + +The plugin creates an `azure_prompt_info` function that you can use in your theme, which displays +the current `$azure_subscription`. It uses two variables to control how that is shown: + +- ZSH_THEME_AZURE_PREFIX: sets the prefix of the azure_subscription. Defaults to ``. + + +``` +RPROMPT='$(azure_prompt_info)' +``` + +## Develop + +On ubuntu get a working environment with : + +` docker run -it -v $(pwd):/mnt -w /mnt ubuntu bash` + +``` +apt install -y curl jq zsh git vim +sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" +curl -sL https://aka.ms/InstallAzureCLIDeb | bash +``` \ No newline at end of file diff --git a/plugins/azure/azure.plugin.zsh b/plugins/azure/azure.plugin.zsh new file mode 100644 index 000000000..7bb173a5c --- /dev/null +++ b/plugins/azure/azure.plugin.zsh @@ -0,0 +1,60 @@ +# AZ Get Subscritions +function azgs() { + az account show --output tsv --query 'name' 2>/dev/null +} + +# AZ Subscription Selection +alias azss="az account set --subscription" + + +function az_subscriptions() { + az account list --all --output tsv --query '[*].name' 2> /dev/null +} + +function _az_subscriptions() { + reply=($(az_subscriptions)) +} +compctl -K _az_subscriptions azss + +# Azure prompt +function azure_prompt_info() { + [[ ! -f "${AZURE_CONFIG_DIR:-$HOME/.azure/azureProfile.json}" ]] && return + # azgs is too expensive, if we have jq, we enable the prompt + (( $+commands[jq] )) || return 1 + azgs=$(jq -r '.subscriptions[] | select(.isDefault==true) .name' ${AZURE_CONFIG_DIR:-$HOME/.azure/azureProfile.json}) + echo "${ZSH_THEME_AZURE_PREFIX:=}" +} + + +# Load az completions +function _az-homebrew-installed() { + # check if Homebrew is installed + (( $+commands[brew] )) || return 1 + + # speculatively check default brew prefix + if [ -h /usr/local/opt/az ]; then + _brew_prefix=/usr/local/opt/az + else + # ok, it is not in the default prefix + # this call to brew is expensive (about 400 ms), so at least let's make it only once + _brew_prefix=$(brew --prefix azure-cli) + fi +} + + +# get az.completion.sh location from $PATH +_az_zsh_completer_path="$commands[az_zsh_completer.sh]" + +# otherwise check common locations +if [[ -z $_az_zsh_completer_path ]]; then + # Homebrew + if _az-homebrew-installed; then + _az_zsh_completer_path=$_brew_prefix/libexec/bin/az.completion.sh + # Linux + else + _az_zsh_completer_path=/etc/bash_completion.d/azure-cli + fi +fi + +[[ -r $_az_zsh_completer_path ]] && source $_az_zsh_completer_path +unset _az_zsh_completer_path _brew_prefix -- cgit v1.2.3-70-g09d2 From 416560c9bf0c03afe6f576ab9e420256843bfb8b Mon Sep 17 00:00:00 2001 From: Richard Mitchell Date: Sun, 12 Feb 2023 11:46:25 -0500 Subject: docs(lib/directories): comment how to disable alias (#11489) --- lib/directories.zsh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib') diff --git a/lib/directories.zsh b/lib/directories.zsh index 5aa1b3d5b..091140626 100644 --- a/lib/directories.zsh +++ b/lib/directories.zsh @@ -3,6 +3,11 @@ setopt auto_pushd setopt pushd_ignore_dups setopt pushdminus +# add (uncommented): +# zstyle ':omz:directories' aliases no +# to your `zshrc` before loading `oh-my-zsh.sh` +# to disable the following aliases and functions + zstyle -T ':omz:directories' aliases || return alias -g ...='../..' -- cgit v1.2.3-70-g09d2 From 574669da6b71462c1f92c75ad75f66476b92974c Mon Sep 17 00:00:00 2001 From: Richard Mitchell Date: Sat, 11 Feb 2023 10:46:31 -0500 Subject: fix(correction)!: remove aliases for non standard commands BREAKING CHANGE: This commit removes aliases for some commands that previously were not being autocorrected. If you are using autocorrection, please check it. --- lib/correction.zsh | 5 ----- 1 file changed, 5 deletions(-) (limited to 'lib') diff --git a/lib/correction.zsh b/lib/correction.zsh index 4259d3418..ba9664fcb 100644 --- a/lib/correction.zsh +++ b/lib/correction.zsh @@ -1,13 +1,8 @@ if [[ "$ENABLE_CORRECTION" == "true" ]]; then alias cp='nocorrect cp' - alias ebuild='nocorrect ebuild' - alias gist='nocorrect gist' - alias heroku='nocorrect heroku' - alias hpodder='nocorrect hpodder' alias man='nocorrect man' alias mkdir='nocorrect mkdir' alias mv='nocorrect mv' - alias mysql='nocorrect mysql' alias sudo='nocorrect sudo' alias su='nocorrect su' -- cgit v1.2.3-70-g09d2 From 8a68bf67720a6a5442ae947d10d74b1dd3558d91 Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Thu, 16 Feb 2023 12:54:23 +0100 Subject: fix(theme-and-appearance): test color ls with $ZSH directory Fixes #11500 --- lib/theme-and-appearance.zsh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index 9b908bef0..c83f58c7b 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -7,32 +7,37 @@ export LSCOLORS="Gxfxcxdxbxegedabagacad" # TODO organise this chaotic logic if [[ "$DISABLE_LS_COLORS" != "true" ]]; then + if [[ -d "$ZSH" ]]; then + _test_dir="$ZSH" + else + _test_dir="." + fi # Find the option for using colors in ls, depending on the version if [[ "$OSTYPE" == netbsd* ]]; then # 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 - gls --color -d . &>/dev/null && alias ls='gls --color=tty' + gls --color -d "$_test_dir" &>/dev/null && alias ls='gls --color=tty' elif [[ "$OSTYPE" == openbsd* ]]; then # 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, so prefer it to "gls". - gls --color -d . &>/dev/null && alias ls='gls --color=tty' - colorls -G -d . &>/dev/null && alias ls='colorls -G' + gls --color -d "$_test_dir" &>/dev/null && alias ls='gls --color=tty' + colorls -G -d "$_test_dir" &>/dev/null && alias ls='colorls -G' elif [[ "$OSTYPE" == (darwin|freebsd)* ]]; then # this is a good alias, it works by default just using $LSCOLORS - ls -G . &>/dev/null && alias ls='ls -G' + ls -G "$_test_dir" &>/dev/null && alias ls='ls -G' # only use coreutils ls if there is a dircolors customization present ($LS_COLORS or .dircolors file) # otherwise, gls will use the default color scheme which is ugly af - [[ -n "$LS_COLORS" || -f "$HOME/.dircolors" ]] && gls --color -d . &>/dev/null && alias ls='gls --color=tty' + [[ -n "$LS_COLORS" || -f "$HOME/.dircolors" ]] && gls --color -d "$_test_dir" &>/dev/null && alias ls='gls --color=tty' else # For GNU ls, we use the default ls color theme. They can later be overwritten by themes. if [[ -z "$LS_COLORS" ]]; then (( $+commands[dircolors] )) && eval "$(dircolors -b)" fi - ls --color -d . &>/dev/null && alias ls='ls --color=tty' || { ls -G . &>/dev/null && alias ls='ls -G' } + ls --color -d "$_test_dir" &>/dev/null && alias ls='ls --color=tty' || { ls -G "$_test_dir" &>/dev/null && alias ls='ls -G' } # Take advantage of $LS_COLORS for completion as well. zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" -- cgit v1.2.3-70-g09d2 From aca048814b2462501ab82938ff2473661182fffb Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Wed, 22 Feb 2023 15:35:12 +0100 Subject: fix(theme-and-appearance): avoid infinite recursion --- lib/theme-and-appearance.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index c83f58c7b..1b64b51d4 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -47,7 +47,7 @@ fi # enable diff color if possible. if command diff --color /dev/null /dev/null &>/dev/null; then function color-diff { - diff --color $@ + command diff --color $@ } alias diff="color-diff" compdef _diff color-diff # compdef is already loaded by this point -- cgit v1.2.3-70-g09d2 From 5cb943eea46d322542c5c2a9f54b201eddc2aa67 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 24 Feb 2023 17:27:23 +0100 Subject: fix(lib): fix return code after expected non-zero exit code (#11524) Fixes #11524 --- lib/directories.zsh | 2 +- lib/vcs_info.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/directories.zsh b/lib/directories.zsh index 091140626..9274b5f5f 100644 --- a/lib/directories.zsh +++ b/lib/directories.zsh @@ -8,7 +8,7 @@ setopt pushdminus # to your `zshrc` before loading `oh-my-zsh.sh` # to disable the following aliases and functions -zstyle -T ':omz:directories' aliases || return +zstyle -T ':omz:directories' aliases || return 0 alias -g ...='../..' alias -g ....='../../..' diff --git a/lib/vcs_info.zsh b/lib/vcs_info.zsh index e60938c14..be6d32ee9 100644 --- a/lib/vcs_info.zsh +++ b/lib/vcs_info.zsh @@ -38,7 +38,7 @@ # due to malicious input as a consequence of CVE-2021-45444, which affects # zsh versions from 5.0.3 to 5.8. # -autoload -Uz +X regexp-replace VCS_INFO_formats 2>/dev/null || return +autoload -Uz +X regexp-replace VCS_INFO_formats 2>/dev/null || return 0 # We use $tmp here because it's already a local variable in VCS_INFO_formats typeset PATCH='for tmp (base base-name branch misc revision subdir) hook_com[$tmp]="${hook_com[$tmp]//\%/%%}"' -- cgit v1.2.3-70-g09d2 From 277f38212aef31a6baba2cf1a0a355af611be5e0 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 24 Feb 2023 20:55:31 +0100 Subject: refactor: reorganize setopts in lib folder --- lib/directories.zsh | 1 + lib/misc.zsh | 8 +++----- lib/theme-and-appearance.zsh | 2 -- 3 files changed, 4 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/directories.zsh b/lib/directories.zsh index 9274b5f5f..13b680c19 100644 --- a/lib/directories.zsh +++ b/lib/directories.zsh @@ -1,4 +1,5 @@ # Changing/making/removing directory +setopt auto_cd setopt auto_pushd setopt pushd_ignore_dups setopt pushdminus diff --git a/lib/misc.zsh b/lib/misc.zsh index 1f637083a..132f33551 100644 --- a/lib/misc.zsh +++ b/lib/misc.zsh @@ -15,8 +15,9 @@ if [[ $DISABLE_MAGIC_FUNCTIONS != true ]]; then done fi -## jobs -setopt long_list_jobs +setopt multios # enable redirect to multiple streams: echo >file1 >file2 +setopt long_list_jobs # show long list format job notifications +setopt interactivecomments # recognize comments env_default 'PAGER' 'less' env_default 'LESS' '-R' @@ -30,6 +31,3 @@ if (( $+commands[ack-grep] )); then elif (( $+commands[ack] )); then alias afind='ack -il' fi - -# recognize comments -setopt interactivecomments diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index 1b64b51d4..208ab9ce5 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -53,8 +53,6 @@ if command diff --color /dev/null /dev/null &>/dev/null; then compdef _diff color-diff # compdef is already loaded by this point fi -setopt auto_cd -setopt multios setopt prompt_subst [[ -n "$WINDOW" ]] && SCREEN_NO="%B$WINDOW%b " || SCREEN_NO="" -- cgit v1.2.3-70-g09d2 From 0ca8907f0e6185545c5e38f77ae2f09ca2a44e77 Mon Sep 17 00:00:00 2001 From: Jannik Date: Sun, 26 Feb 2023 20:37:03 +0100 Subject: fix(lib): fix case-insensitive completion for zsh 5.9 (#11526) --- lib/completion.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/completion.zsh b/lib/completion.zsh index 2c5695487..63379b53f 100644 --- a/lib/completion.zsh +++ b/lib/completion.zsh @@ -18,9 +18,9 @@ if [[ "$CASE_SENSITIVE" = true ]]; then zstyle ':completion:*' matcher-list 'r:|=*' 'l:|=* r:|=*' else if [[ "$HYPHEN_INSENSITIVE" = true ]]; then - zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|=*' 'l:|=* r:|=*' + zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]-_}={[:upper:][:lower:]_-}' 'r:|=*' 'l:|=* r:|=*' else - zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*' + zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'r:|=*' 'l:|=* r:|=*' fi fi unset CASE_SENSITIVE HYPHEN_INSENSITIVE -- cgit v1.2.3-70-g09d2 From 5bf7f9c83325a6cb2752e14ca01a574dbeef206e Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 3 Mar 2023 12:34:31 +0100 Subject: fix(lib): use `$BROWSER` in `open_command` if set (#11532) Fixes #11098 --- lib/functions.zsh | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib') diff --git a/lib/functions.zsh b/lib/functions.zsh index 6e1faa6aa..1d85ea38a 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -30,6 +30,13 @@ function open_command() { ;; esac + # If a URL is passed, $BROWSER might be set to a local browser within SSH. + # See https://github.com/ohmyzsh/ohmyzsh/issues/11098 + if [[ -n "$BROWSER" && "$1" = (http|https)://* ]]; then + "$BROWSER" "$@" + return + fi + ${=open_cmd} "$@" &>/dev/null } -- cgit v1.2.3-70-g09d2 From 95d0c4b603e0c880bcf20bc9211b2162e94ed925 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 3 Mar 2023 14:38:50 +0100 Subject: refactor(theme-and-appearance): reorganize and clean up logic (#11529) Co-authored-by: Andrew Janke Co-authored-by: Marcelo Parada Co-authored-by: Uy Ha Co-authored-by: Valentin Uveges --- lib/theme-and-appearance.zsh | 135 ++++++++++++++++++++++++++----------------- 1 file changed, 81 insertions(+), 54 deletions(-) (limited to 'lib') diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index 208ab9ce5..985d3bc11 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -1,66 +1,93 @@ -# ls colors +# Sets color variable such as $fg, $bg, $color and $reset_color autoload -U colors && colors -# Enable ls colors -export LSCOLORS="Gxfxcxdxbxegedabagacad" +# Expand variables and commands in PROMPT variables +setopt prompt_subst -# TODO organise this chaotic logic +# Prompt function theming defaults +ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Beginning of the git prompt, before the branch name +ZSH_THEME_GIT_PROMPT_SUFFIX=")" # End of the git prompt +ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty +ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean +ZSH_THEME_RUBY_PROMPT_PREFIX="(" +ZSH_THEME_RUBY_PROMPT_SUFFIX=")" -if [[ "$DISABLE_LS_COLORS" != "true" ]]; then - if [[ -d "$ZSH" ]]; then - _test_dir="$ZSH" - else - _test_dir="." - fi - # Find the option for using colors in ls, depending on the version - if [[ "$OSTYPE" == netbsd* ]]; then - # 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 - gls --color -d "$_test_dir" &>/dev/null && alias ls='gls --color=tty' - elif [[ "$OSTYPE" == openbsd* ]]; then - # 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, so prefer it to "gls". - gls --color -d "$_test_dir" &>/dev/null && alias ls='gls --color=tty' - colorls -G -d "$_test_dir" &>/dev/null && alias ls='colorls -G' - elif [[ "$OSTYPE" == (darwin|freebsd)* ]]; then - # this is a good alias, it works by default just using $LSCOLORS - ls -G "$_test_dir" &>/dev/null && alias ls='ls -G' - # only use coreutils ls if there is a dircolors customization present ($LS_COLORS or .dircolors file) - # otherwise, gls will use the default color scheme which is ugly af - [[ -n "$LS_COLORS" || -f "$HOME/.dircolors" ]] && gls --color -d "$_test_dir" &>/dev/null && alias ls='gls --color=tty' - else - # For GNU ls, we use the default ls color theme. They can later be overwritten by themes. - if [[ -z "$LS_COLORS" ]]; then - (( $+commands[dircolors] )) && eval "$(dircolors -b)" +# Use diff --color if available +if command diff --color /dev/null{,} &>/dev/null; then + function diff { + command diff --color "$@" + } +fi + + +# Don't set ls coloring if disabled +[[ "$DISABLE_LS_COLORS" != true ]] || return 0 + +function test-ls-args { + local cmd="$1" # ls, gls, colorls, ... + local args="${@[2,-1]}" # arguments except the first one + command "$cmd" "$args" /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 + 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 + [[ -n "$LS_COLORS" || -f "$HOME/.dircolors" ]] \ + && 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 - ls --color -d "$_test_dir" &>/dev/null && alias ls='ls --color=tty' || { ls -G "$_test_dir" &>/dev/null && alias ls='ls -G' } +unfunction test-ls-args - # Take advantage of $LS_COLORS for completion as well. - zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" - fi -fi -# enable diff color if possible. -if command diff --color /dev/null /dev/null &>/dev/null; then - function color-diff { - command diff --color $@ - } - alias diff="color-diff" - compdef _diff color-diff # compdef is already loaded by this point -fi +# Default coloring for BSD-based ls +export LSCOLORS="Gxfxcxdxbxegedabagacad" -setopt prompt_subst +# 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=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=37;41:sg=30;43:tw=30;42:ow=34;42:" + fi +fi -[[ -n "$WINDOW" ]] && SCREEN_NO="%B$WINDOW%b " || SCREEN_NO="" +# Take advantage of $LS_COLORS for completion as well. +function omz_set_completion_colors { + zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" + add-zsh-hook -d precmd omz_set_completion_colors + unfunction omz_set_completion_colors +} -# git theming default: Variables for theming the git info prompt -ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Prefix at the very beginning of the prompt, before the branch name -ZSH_THEME_GIT_PROMPT_SUFFIX=")" # At the very end of the prompt -ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty -ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean -ZSH_THEME_RUBY_PROMPT_PREFIX="(" -ZSH_THEME_RUBY_PROMPT_SUFFIX=")" +autoload -Uz add-zsh-hook +add-zsh-hook precmd omz_set_completion_colors -- cgit v1.2.3-70-g09d2 From d342b353e32091ef7384b86fd86b1a88dbd44609 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Tue, 7 Mar 2023 18:49:17 +0100 Subject: fix(init): set completion colors on theme load, not with `precmd` This fixes an edge case where the user actually sets zstyle ':completion:*' list-colors in their zshrc, but the previous code used a precmd hook, which would override the user changes. With this change our modifications will be set in the init script, after the theme loads, so that later changes can affect our defaults. Note that this will not be run for users on plugin managers, as these don't generally run our init script. --- lib/theme-and-appearance.zsh | 10 ---------- oh-my-zsh.sh | 3 +++ 2 files changed, 3 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index 985d3bc11..e245570e3 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -81,13 +81,3 @@ if [[ -z "$LS_COLORS" ]]; then export LS_COLORS="di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=37;41:sg=30;43:tw=30;42:ow=34;42:" fi fi - -# Take advantage of $LS_COLORS for completion as well. -function omz_set_completion_colors { - zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" - add-zsh-hook -d precmd omz_set_completion_colors - unfunction omz_set_completion_colors -} - -autoload -Uz add-zsh-hook -add-zsh-hook precmd omz_set_completion_colors diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 98bda8c8b..363cfca8b 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -189,3 +189,6 @@ if [[ -n "$ZSH_THEME" ]]; then echo "[oh-my-zsh] theme '$ZSH_THEME' not found" fi fi + +# set completion colors to be the same as `ls`, after theme has been loaded +[[ -z "$LS_COLORS" ]] || zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" -- cgit v1.2.3-70-g09d2 From 72732a224e886933df6b64a49ec6f5e94c884612 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 12 Mar 2023 15:47:58 +0100 Subject: fix(lib): set equivalent LS_COLORS and LSCOLORS variables As reported by https://geoff.greer.fm/lscolors Fixes #11554 --- lib/theme-and-appearance.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index e245570e3..d8859b04c 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -78,6 +78,6 @@ if [[ -z "$LS_COLORS" ]]; then && source <(dircolors -b "$HOME/.dircolors") \ || source <(dircolors -b) else - export LS_COLORS="di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=37;41:sg=30;43:tw=30;42:ow=34;42:" + 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 -- cgit v1.2.3-70-g09d2