Skip to content

Commit

Permalink
Merge branch 'pull/95'
Browse files Browse the repository at this point in the history
Closes: #95

* pull/95:
  docs: update README authors and CHANGELOG
  refactor(dotfiles): use Zsh's own option parsing instead of hand-rolling
  style(dotfiles): apply style fixes
  fix(dotfiles): make `colors help` output compact again
  feat(dotfiles): add `colors rand` subcommand.
  • Loading branch information
wincent committed Dec 22, 2020
2 parents ff3f741 + b54c1c5 commit 05c65ac
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2020-12-21

- [Zsh]: Added `rand` subcommand to `color` function (pull request [#95](https://github.com/wincent/wincent/pull/95) from Michael Lohmann).

## 2020-10-22

- [Zsh]: Dropped `groot` alias in favor of `git root` function.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ The repo is written and maintained by Greg Hurrell <[greg@hurrell.net](mailto
- Jonathan Wilkins
- Mark Stenglein
- Matthew Byrne
- Michael Lohmann
- Stone C. Lasley
- Victor Igor
- Zac Collier
Expand Down
29 changes: 22 additions & 7 deletions aspects/dotfiles/files/.zsh/colors
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ luma() {
color() {
emulate -L zsh

local SCHEME="$1"
local SCHEME
local BASE16_DIR=~/.zsh/base16-shell/scripts
local BASE16_CONFIG_PREVIOUS="${__WINCENT[BASE16_CONFIG]}.previous"
local STATUS=0
Expand Down Expand Up @@ -83,33 +83,48 @@ color() {
fi
}

zparseopts -D -E -- q=QUIET -quiet=QUIET

if [ $# -eq 0 ]; then
if [ -s "$__WINCENT[BASE16_CONFIG]" ]; then
cat "$__WINCENT[BASE16_CONFIG]"
local SCHEME=$(head -1 "$__WINCENT[BASE16_CONFIG]")
SCHEME=$(head -1 "$__WINCENT[BASE16_CONFIG]")
__color "$SCHEME"
return
else
SCHEME=help
fi
else
SCHEME=$1
fi

local ALL_SCHEMES=($(find "$BASE16_DIR" -name 'base16-*.sh' | \
sed -E 's|.+/base16-||' | \
sed -E 's/\.sh//' | \
grep "${2:-.}" | \
sort
))

case "$SCHEME" in
help)
echo 'color (show current scheme)'
echo 'color default-dark|grayscale-light|... (switch to scheme)'
echo 'color help (show this help)'
echo 'color ls [pattern] (list available schemes)'
echo 'color rand [-q/--quiet] [pattern] (choose a random scheme)'
return
;;
ls)
find "$BASE16_DIR" -name 'base16-*.sh' | \
sed -E 's|.+/base16-||' | \
sed -E 's/\.sh//' | \
grep "${2:-.}" | \
sort | \
printf '%s\n' "${ALL_SCHEMES[@]}" | \
column
;;
rand)
local RANDOM_COLOR=${ALL_SCHEMES[$(($RANDOM % ${#ALL_SCHEMES[@]} + 1))]}
if [[ ${#QUIET} -eq 0 ]]; then
echo "$RANDOM_COLOR"
fi
__color "$RANDOM_COLOR"
;;
-)
if [[ -s "$BASE16_CONFIG_PREVIOUS" ]]; then
local PREVIOUS_SCHEME=$(head -1 "$BASE16_CONFIG_PREVIOUS")
Expand Down

0 comments on commit 05c65ac

Please sign in to comment.