Skip to content

Commit d351d24

Browse files
Merge pull request #1 from edouard-lopez/refactor-to-save-n-restore-previous-theme
refactor to save n restore previous theme
2 parents 82d0d9e + bf73750 commit d351d24

File tree

6 files changed

+132
-65
lines changed

6 files changed

+132
-65
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
## Configuration
1010

11-
Edit `~/.config/fish/config.fish` to load a variant, _e.g._:
11+
Declare the variant you want as a universal variable, _e.g._:
1212

13-
source $__fish_config_dir/conf.d/ayu-light.fish
13+
set --universal ayu_variant light && ayu_load_theme
1414

1515
## Variants
1616

conf.d/ayu-dark.fish

+22-21
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
# AYU THEME: DARK
2-
set fish_color_autosuggestion 4D5566 # ayu:common.ui autosuggestions
3-
set fish_color_command 39BAE6 # ayu:syntax.tag commands
4-
set fish_color_comment 626A73 # ayu:syntax.comment code comments
5-
set fish_color_cwd 59C2FF # ayu:syntax.entity current working directory in the default prompt
6-
set fish_color_end F29668 # ayu:common.operator process separators like ';' and '&'
7-
set fish_color_error FF3333 # ayu:syntax.error highlight potential errors
8-
set fish_color_escape 95E6CB # ayu:syntax.regexp highlight character escapes like '\n' and '\x70'
9-
set fish_color_match F07178 # ayu:syntax.markup highlight matching parenthesis
10-
set fish_color_normal B3B1AD # ayu:common.fg default color
11-
set fish_color_operator E6B450 # ayu:syntax.accent parameter expansion operators like '*' and '~'
12-
set fish_color_param B3B1AD # ayu:common.fg regular command parameters
13-
set fish_color_quote C2D94C # ayu:syntax.string quoted blocks of text
14-
set fish_color_redirection FFEE99 # ayu:syntax.constant IO redirections
15-
set fish_color_search_match --background E6B450 # ayu:syntax.accent highlight history search matches and the selected pager item (must be a background)
16-
set fish_color_selection E6B450 # ayu:syntax.accent when selecting text (in vi visual mode)
1+
function enable_ayu_theme_dark
2+
set --universal fish_color_autosuggestion 4D5566 # ayu:common.ui autosuggestions
3+
set --universal fish_color_command 39BAE6 # ayu:syntax.tag commands
4+
set --universal fish_color_comment 626A73 # ayu:syntax.comment code comments
5+
set --universal fish_color_cwd 59C2FF # ayu:syntax.entity current working directory in the default prompt
6+
set --universal fish_color_end F29668 # ayu:syntax.operator process separators like ';' and '&'
7+
set --universal fish_color_error FF3333 # ayu:syntax.error highlight potential errors
8+
set --universal fish_color_escape 95E6CB # ayu:syntax.regexp highlight character escapes like '\n' and '\x70'
9+
set --universal fish_color_match F07178 # ayu:syntax.markup highlight matching parenthesis
10+
set --universal fish_color_normal B3B1AD # ayu:common.fg default color
11+
set --universal fish_color_operator E6B450 # ayu:syntax.accent parameter expansion operators like '*' and '~'
12+
set --universal fish_color_param B3B1AD # ayu:common.fg regular command parameters
13+
set --universal fish_color_quote C2D94C # ayu:syntax.string quoted blocks of text
14+
set --universal fish_color_redirection FFEE99 # ayu:syntax.constant IO redirections
15+
set --universal fish_color_search_match --background E6B450 # ayu:syntax.accent highlight history search matches and the selected pager item (must be a background)
16+
set --universal fish_color_selection E6B450 # ayu:syntax.accent when selecting text (in vi visual mode)
1717

18-
# color for fish default prompts item
19-
set fish_color_cancel 0A0E14 # ayu:common.bg the '^C' indicator on a canceled command
20-
set fish_color_host FFEE99 # ayu:syntax.constant current host system in some of fish default prompts
21-
set fish_color_host_remote FFEE99 # ayu:syntax.constant current host system in some of fish default prompts, if fish is running remotely (via ssh or similar)
22-
set fish_color_user FF8F40 # ayu:syntax.keyword current username in some of fish default prompts
18+
# color for fish default prompts item
19+
set --universal fish_color_cancel 0A0E14 # ayu:common.bg the '^C' indicator on a canceled command
20+
set --universal fish_color_host FFEE99 # ayu:syntax.constant current host system in some of fish default prompts
21+
set --universal fish_color_host_remote FFEE99 # ayu:syntax.constant current host system in some of fish default prompts, if fish is running remotely (via ssh or similar)
22+
set --universal fish_color_user FF8F40 # ayu:syntax.keyword current username in some of fish default prompts
23+
end

conf.d/ayu-light.fish

+22-21
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
# AYU THEME: LIGHT
2-
set fish_color_autosuggestion 8A9199 # ayu:common.ui autosuggestions
3-
set fish_color_command 55B4D4 # ayu:syntax.tag commands
4-
set fish_color_comment ABB0B6 # ayu:syntax.comment code comments
5-
set fish_color_cwd 399EE6 # ayu:syntax.entity current working directory in the default prompt
6-
set fish_color_end ED9366 # ayu:common.operator process separators like ';' and '&'
7-
set fish_color_error F51818 # ayu:syntax.error highlight potential errors
8-
set fish_color_escape 4CBF99 # ayu:syntax.regexp highlight character escapes like '\n' and '\x70'
9-
set fish_color_match F07171 # ayu:syntax.markup highlight matching parenthesis
10-
set fish_color_normal 575F66 # ayu:common.fg default color
11-
set fish_color_operator FF9940 # ayu:syntax.accent parameter expansion operators like '*' and '~'
12-
set fish_color_param 575F66 # ayu:common.fg regular command parameters
13-
set fish_color_quote 86B300 # ayu:syntax.string quoted blocks of text
14-
set fish_color_redirection A37ACC # ayu:syntax.constant IO redirections
15-
set fish_color_search_match --background FF9940 # ayu:syntax.accent highlight history search matches and the selected pager item (must be a background)
16-
set fish_color_selection FF9940 # ayu:syntax.accent when selecting text (in vi visual mode)
1+
function enable_ayu_theme_light
2+
set --universal fish_color_autosuggestion 8A9199 # ayu:common.ui autosuggestions
3+
set --universal fish_color_command 55B4D4 # ayu:syntax.tag commands
4+
set --universal fish_color_comment ABB0B6 # ayu:syntax.comment code comments
5+
set --universal fish_color_cwd 399EE6 # ayu:syntax.entity current working directory in the default prompt
6+
set --universal fish_color_end ED9366 # ayu:syntax.operator process separators like ';' and '&'
7+
set --universal fish_color_error F51818 # ayu:syntax.error highlight potential errors
8+
set --universal fish_color_escape 4CBF99 # ayu:syntax.regexp highlight character escapes like '\n' and '\x70'
9+
set --universal fish_color_match F07171 # ayu:syntax.markup highlight matching parenthesis
10+
set --universal fish_color_normal 575F66 # ayu:common.fg default color
11+
set --universal fish_color_operator FF9940 # ayu:syntax.accent parameter expansion operators like '*' and '~'
12+
set --universal fish_color_param 575F66 # ayu:common.fg regular command parameters
13+
set --universal fish_color_quote 86B300 # ayu:syntax.string quoted blocks of text
14+
set --universal fish_color_redirection A37ACC # ayu:syntax.constant IO redirections
15+
set --universal fish_color_search_match --background FF9940 # ayu:syntax.accent highlight history search matches and the selected pager item (must be a background)
16+
set --universal fish_color_selection FF9940 # ayu:syntax.accent when selecting text (in vi visual mode)
1717

18-
# color for fish default prompts item
19-
set fish_color_cancel FAFAFA # ayu:common.bg the '^C' indicator on a canceled command
20-
set fish_color_host A37ACC # ayu:syntax.constant current host system in some of fish default prompts
21-
set fish_color_host_remote A37ACC # ayu:syntax.constant current host system in some of fish default prompts, if fish is running remotely (via ssh or similar)
22-
set fish_color_user FA8D3E # ayu:syntax.keyword current username in some of fish default prompts
18+
# color for fish default prompts item
19+
set --universal fish_color_cancel FAFAFA # ayu:common.bg the '^C' indicator on a canceled command
20+
set --universal fish_color_host A37ACC # ayu:syntax.constant current host system in some of fish default prompts
21+
set --universal fish_color_host_remote A37ACC # ayu:syntax.constant current host system in some of fish default prompts, if fish is running remotely (via ssh or similar)
22+
set --universal fish_color_user FA8D3E # ayu:syntax.keyword current username in some of fish default prompts
23+
end

conf.d/ayu-mirage.fish

+22-21
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
# AYU THEME: MIRAGE
2-
set fish_color_autosuggestion 707A8C # ayu:common.ui autosuggestions
3-
set fish_color_command 5CCFE6 # ayu:syntax.tag commands
4-
set fish_color_comment 5C6773 # ayu:syntax.comment code comments
5-
set fish_color_cwd 73D0FF # ayu:syntax.entity current working directory in the default prompt
6-
set fish_color_end F29E74 # ayu:common.operator process separators like ';' and '&'
7-
set fish_color_error FF3333 # ayu:syntax.error highlight potential errors
8-
set fish_color_escape 95E6CB # ayu:syntax.regexp highlight character escapes like '\n' and '\x70'
9-
set fish_color_match F28779 # ayu:syntax.markup highlight matching parenthesis
10-
set fish_color_normal CBCCC6 # ayu:common.fg default color
11-
set fish_color_operator FFCC66 # ayu:syntax.accent parameter expansion operators like '*' and '~'
12-
set fish_color_param CBCCC6 # ayu:common.fg regular command parameters
13-
set fish_color_quote BAE67E # ayu:syntax.string quoted blocks of text
14-
set fish_color_redirection D4BFFF # ayu:syntax.constant IO redirections
15-
set fish_color_search_match --background FFCC66 # ayu:syntax.accent highlight history search matches and the selected pager item (must be a background)
16-
set fish_color_selection FFCC66 # ayu:syntax.accent when selecting text (in vi visual mode)
1+
function enable_ayu_theme_mirage
2+
set --universal fish_color_autosuggestion 707A8C # ayu:common.ui autosuggestions
3+
set --universal fish_color_command 5CCFE6 # ayu:syntax.tag commands
4+
set --universal fish_color_comment 5C6773 # ayu:syntax.comment code comments
5+
set --universal fish_color_cwd 73D0FF # ayu:syntax.entity current working directory in the default prompt
6+
set --universal fish_color_end F29E74 # ayu:syntax.operator process separators like ';' and '&'
7+
set --universal fish_color_error FF3333 # ayu:syntax.error highlight potential errors
8+
set --universal fish_color_escape 95E6CB # ayu:syntax.regexp highlight character escapes like '\n' and '\x70'
9+
set --universal fish_color_match F28779 # ayu:syntax.markup highlight matching parenthesis
10+
set --universal fish_color_normal CBCCC6 # ayu:common.fg default color
11+
set --universal fish_color_operator FFCC66 # ayu:syntax.accent parameter expansion operators like '*' and '~'
12+
set --universal fish_color_param CBCCC6 # ayu:common.fg regular command parameters
13+
set --universal fish_color_quote BAE67E # ayu:syntax.string quoted blocks of text
14+
set --universal fish_color_redirection D4BFFF # ayu:syntax.constant IO redirections
15+
set --universal fish_color_search_match --background FFCC66 # ayu:syntax.accent highlight history search matches and the selected pager item (must be a background)
16+
set --universal fish_color_selection FFCC66 # ayu:syntax.accent when selecting text (in vi visual mode)
1717

18-
# color for fish default prompts item
19-
set fish_color_cancel 1F2430 # ayu:common.bg the '^C' indicator on a canceled command
20-
set fish_color_host D4BFFF # ayu:syntax.constant current host system in some of fish default prompts
21-
set fish_color_host_remote D4BFFF # ayu:syntax.constant current host system in some of fish default prompts, if fish is running remotely (via ssh or similar)
22-
set fish_color_user FFA759 # ayu:syntax.keyword current username in some of fish default prompts
18+
# color for fish default prompts item
19+
set --universal fish_color_cancel 1F2430 # ayu:common.bg the '^C' indicator on a canceled command
20+
set --universal fish_color_host D4BFFF # ayu:syntax.constant current host system in some of fish default prompts
21+
set --universal fish_color_host_remote D4BFFF # ayu:syntax.constant current host system in some of fish default prompts, if fish is running remotely (via ssh or similar)
22+
set --universal fish_color_user FFA759 # ayu:syntax.keyword current username in some of fish default prompts
23+
end

conf.d/ayu.fish

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
function ayu_load_theme
2+
set --query ayu_path || set --local ayu_path $__fish_config_dir
3+
4+
switch $ayu_variant
5+
case light
6+
source $ayu_path/conf.d/ayu-light.fish && enable_ayu_theme_light
7+
and colorize "Ayu %s light %s enabled!\n"
8+
case dark
9+
source $ayu_path/conf.d/ayu-dark.fish && enable_ayu_theme_dark
10+
and colorize "Ayu %s dark %s enabled!\n"
11+
case mirage
12+
source $ayu_path/conf.d/ayu-mirage.fish && enable_ayu_theme_mirage
13+
and colorize "Ayu %s mirage %s enabled!\n"
14+
case '*'
15+
echo '⚠️ Invalid variant, choose among: light, dark or mirage'
16+
end
17+
end
18+
19+
function colorize \
20+
--argument-names text
21+
printf $text (set_color $fish_color_quote --reverse) (set_color normal)
22+
end
23+
24+
function _ayu_save_current_theme
25+
set --local previous_theme_file $__fish_config_dir/functions/_ayu_restore_previous_theme.fish
26+
27+
test -e $previous_theme_file && command rm -f $previous_theme_file
28+
touch $previous_theme_file
29+
30+
echo 'function _ayu_restore_previous_theme' > $previous_theme_file
31+
set color_variables (set --names | grep fish_color)
32+
for color_name in $color_variables
33+
set --local color_value $$color_name
34+
printf "\tset --universal $color_name $color_value\n" >> $previous_theme_file
35+
end
36+
echo 'end' >> $previous_theme_file
37+
end
38+
39+
function _ayu_install --on-event ayu_install
40+
_ayu_save_current_theme
41+
and echo 'Previous theme saved! 🎉'
42+
end
43+
44+
function _ayu_uninstall --on-event ayu_uninstall
45+
functions --erase enable_ayu_theme_light
46+
functions --erase enable_ayu_theme_dark
47+
functions --erase enable_ayu_theme_mirage
48+
49+
set --local previous_theme_file $__fish_config_dir/functions/_ayu_restore_previous_theme.fish
50+
source $previous_theme_file && _ayu_restore_previous_theme
51+
command rm -f $previous_theme_file
52+
functions --erase _ayu_restore_previous_theme
53+
set --erase ayu_variant
54+
end
55+
56+
function ayu_display_colorscheme
57+
set color_vars (set --names | grep fish_color)
58+
for color_var in $color_vars
59+
printf "%-30s %s\n" \
60+
$color_var \
61+
(set_color $$color_var --reverse)"$$color_var"(set_color normal)
62+
end
63+
end

version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.0.0

0 commit comments

Comments
 (0)