1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-29 13:16:51 +08:00

feat(theme-and-appearance): allow disabling gnu-ls in bsd

To disable gnu-ls (`gls`) even if it's installed in freeBSD and macOS
you can set it up with:
```zsh
zstyle ':omz:lib:theme-and-appearance' gnu-ls no
```

Closes #11647
This commit is contained in:
Carlo Sala 2023-05-02 12:41:01 +02:00
parent 5a3f565e7d
commit c5208867f1
2 changed files with 30 additions and 19 deletions

View File

@ -40,6 +40,7 @@ To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://twi
- [Manual Installation](#manual-installation) - [Manual Installation](#manual-installation)
- [Installation Problems](#installation-problems) - [Installation Problems](#installation-problems)
- [Custom Plugins and Themes](#custom-plugins-and-themes) - [Custom Plugins and Themes](#custom-plugins-and-themes)
- [Disable GNU ls in macOS and freeBSD systems](#disable-gnu-ls)
- [Skip aliases](#skip-aliases) - [Skip aliases](#skip-aliases)
- [Getting Updates](#getting-updates) - [Getting Updates](#getting-updates)
- [Updates verbosity](#updates-verbosity) - [Updates verbosity](#updates-verbosity)
@ -278,6 +279,18 @@ 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/`. 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/`.
### Disable GNU ls in macOS and freeBSD systems
<a name="disable-gnu-ls"></a>
The default behaviour in Oh My Zsh is to use GNU `ls` even in macOS and freeBSD systems if it's installed (as
`gls` command) when enabling colorized `ls` in `lib/theme-and-appearance.zsh`. If you want to disable this
behaviour you can use zstyle-based config before sourcing `oh-my-zsh.sh`:
```zsh
zstyle ':omz:lib:theme-and-appearance' gnu-ls no
```
### Skip aliases ### Skip aliases
<a name="remove-directories-aliases"></a> <a name="remove-directories-aliases"></a>

View File

@ -20,10 +20,25 @@ if command diff --color /dev/null{,} &>/dev/null; then
} }
fi fi
# Don't set ls coloring if disabled # Don't set ls coloring if disabled
[[ "$DISABLE_LS_COLORS" != true ]] || return 0 [[ "$DISABLE_LS_COLORS" != true ]] || return 0
# 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"
fi
fi
function test-ls-args { function test-ls-args {
local cmd="$1" # ls, gls, colorls, ... local cmd="$1" # ls, gls, colorls, ...
local args="${@[2,-1]}" # arguments except the first one local args="${@[2,-1]}" # arguments except the first one
@ -50,7 +65,7 @@ case "$OSTYPE" in
test-ls-args ls -G && alias ls='ls -G' test-ls-args ls -G && alias ls='ls -G'
# Only use GNU ls if installed and there are user defaults for $LS_COLORS, # Only use GNU ls if installed and there are user defaults for $LS_COLORS,
# as the default coloring scheme is not very pretty # as the default coloring scheme is not very pretty
[[ -n "$LS_COLORS" || -f "$HOME/.dircolors" ]] \ zstyle -T ':omz:lib:theme-and-appearance' gnu-ls \
&& test-ls-args gls --color \ && test-ls-args gls --color \
&& alias ls='gls --color=tty' && alias ls='gls --color=tty'
;; ;;
@ -64,20 +79,3 @@ case "$OSTYPE" in
esac esac
unfunction test-ls-args unfunction test-ls-args
# 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"
fi
fi