Add .config/fish/conf.d/you_should_use.fish
Add .config/fish/functions/__ysu__check_aliases.fish Add .config/fish/functions/__ysu__check_git_aliases.fish Add .config/fish/functions/__ysu__check_hardcore.fish Add .config/fish/functions/__ysu__flush_buffer.fish Add .config/fish/functions/__ysu__get_field.fish Add .config/fish/functions/__ysu__message.fish Add .config/fish/functions/__ysu__set_default.fish Add .config/fish/functions/__ysu__set_field.fish Add .config/fish/functions/__ysu__write_buffer.fish
This commit is contained in:
parent
a1bcb57fe3
commit
60cb5740d7
10 changed files with 115 additions and 0 deletions
14
dot_config/fish/conf.d/you_should_use.fish
Normal file
14
dot_config/fish/conf.d/you_should_use.fish
Normal file
|
@ -0,0 +1,14 @@
|
|||
set --global FISH_YOU_SHOULD_USE_VERSION "1.2.0"
|
||||
|
||||
__ysu__set_default NONE (set_color normal)
|
||||
__ysu__set_default BOLD (set_color -o normal)
|
||||
__ysu__set_default RED (set_color red)
|
||||
__ysu__set_default YELLOW (set_color yellow)
|
||||
__ysu__set_default VIOLET (set_color magenta)
|
||||
|
||||
set --global YSU__MESSAGE_POSITION "after"
|
||||
set --global YSU__HARDCORE_MODE false
|
||||
|
||||
functions -q __ysu__check_aliases
|
||||
functions -q __ysu__check_git_aliases
|
||||
functions -q __ysu__flush_buffer
|
24
dot_config/fish/functions/__ysu__check_aliases.fish
Normal file
24
dot_config/fish/functions/__ysu__check_aliases.fish
Normal file
|
@ -0,0 +1,24 @@
|
|||
function __ysu__check_aliases \
|
||||
--on-event fish_preexec
|
||||
string match --quiet "sudo *" "$argv"; and return
|
||||
|
||||
set --local found false
|
||||
alias | sort | while read entry
|
||||
set entry (string replace "=" "" "$entry")
|
||||
set --local tokens (string split --max 2 " " "$entry")
|
||||
set --local key "$tokens[2]"
|
||||
set --local escaped_key (string escape --no-quote --style=regex "$key")
|
||||
|
||||
string match --quiet --regex "$escaped_key" "$YSU__IGNORED_GLOBAL_ALIASES"; and continue
|
||||
|
||||
set --local value (string replace --regex '(?:[\"|\']([^,]*)[\"|\'])' '$1' "$tokens[3]")
|
||||
set --local escaped_value (string escape --no-quote --style=regex "$value")
|
||||
|
||||
if string match --quiet --regex "(?<=^|\s)$escaped_value(?=\s|\$)" "$argv"
|
||||
__ysu__message "alias" "$value" "$key"
|
||||
set found true
|
||||
end
|
||||
end
|
||||
|
||||
"$found"; and __ysu__check_hardcore
|
||||
end
|
23
dot_config/fish/functions/__ysu__check_git_aliases.fish
Normal file
23
dot_config/fish/functions/__ysu__check_git_aliases.fish
Normal file
|
@ -0,0 +1,23 @@
|
|||
function __ysu__check_git_aliases \
|
||||
--on-event fish_preexec
|
||||
string match --quiet "sudo *" "$argv"; and return
|
||||
|
||||
if string match --quiet --regex "git *" "$argv"
|
||||
set --local found false
|
||||
git config --get-regexp "^alias\..+\$" | sort | while read key value
|
||||
set key (string split --max 2 "." "$key")[2]
|
||||
set --local escaped_key (string escape --no-quote --style=regex "$key")
|
||||
|
||||
string match --quiet --regex "$escaped_key" "$YSU__IGNORED_GIT_ALIASES"; and continue
|
||||
|
||||
set --local escaped_value (string escape --no-quote --style=regex "$value")
|
||||
|
||||
if string match --quiet --regex "git $escaped_value(?=\s|\$)" "$argv"
|
||||
__ysu__message "git alias" "$value" "git $key"
|
||||
set found true
|
||||
end
|
||||
end
|
||||
|
||||
"$found"; and __ysu__check_hardcore
|
||||
end
|
||||
end
|
6
dot_config/fish/functions/__ysu__check_hardcore.fish
Normal file
6
dot_config/fish/functions/__ysu__check_hardcore.fish
Normal file
|
@ -0,0 +1,6 @@
|
|||
function __ysu__check_hardcore
|
||||
if "$YSU__HARDCORE_MODE"
|
||||
__ysu__write_buffer \
|
||||
"$BOLD$REDYou Should Use hardcore mode enabled. Use your aliases!"
|
||||
end
|
||||
end
|
8
dot_config/fish/functions/__ysu__flush_buffer.fish
Normal file
8
dot_config/fish/functions/__ysu__flush_buffer.fish
Normal file
|
@ -0,0 +1,8 @@
|
|||
function __ysu__flush_buffer \
|
||||
--on-event fish_prompt
|
||||
if test -n "$__BUFFER"
|
||||
printf "$__BUFFER"
|
||||
end
|
||||
|
||||
set __BUFFER ""
|
||||
end
|
4
dot_config/fish/functions/__ysu__get_field.fish
Normal file
4
dot_config/fish/functions/__ysu__get_field.fish
Normal file
|
@ -0,0 +1,4 @@
|
|||
function __ysu__get_field \
|
||||
--argument-names dict key
|
||||
eval echo \$$dict'__'$key
|
||||
end
|
7
dot_config/fish/functions/__ysu__message.fish
Normal file
7
dot_config/fish/functions/__ysu__message.fish
Normal file
|
@ -0,0 +1,7 @@
|
|||
function __ysu__message \
|
||||
--argument-names alias_type command alias
|
||||
# zero-width space delinates the end of a variable and the beginning of the message
|
||||
__ysu__write_buffer "\
|
||||
$BOLD$YELLOWFound existing $alias_type for \"$VIOLET$command$YELLOW\".
|
||||
You should use: \"$alias\"\n"
|
||||
end
|
7
dot_config/fish/functions/__ysu__set_default.fish
Normal file
7
dot_config/fish/functions/__ysu__set_default.fish
Normal file
|
@ -0,0 +1,7 @@
|
|||
function __ysu__set_default \
|
||||
--no-scope-shadowing \
|
||||
--argument-names var default
|
||||
if not set -q "$var"
|
||||
set --global "$var" "$default"
|
||||
end
|
||||
end
|
4
dot_config/fish/functions/__ysu__set_field.fish
Normal file
4
dot_config/fish/functions/__ysu__set_field.fish
Normal file
|
@ -0,0 +1,4 @@
|
|||
function __ysu__set_field \
|
||||
--argument-names dict key value
|
||||
set --global $dict'__'$key $value
|
||||
end
|
18
dot_config/fish/functions/__ysu__write_buffer.fish
Normal file
18
dot_config/fish/functions/__ysu__write_buffer.fish
Normal file
|
@ -0,0 +1,18 @@
|
|||
function __ysu__write_buffer \
|
||||
--argument-names contents
|
||||
set --global __BUFFER "$contents$__BUFFER\n"
|
||||
|
||||
set --local position "before"
|
||||
if set -q YSU__MESSAGE_POSITION
|
||||
set position "$YSU__MESSAGE_POSITION"
|
||||
end
|
||||
|
||||
if [ "$position" = "before" ]
|
||||
__ysu__flush_buffer
|
||||
else if [ "$position" != "after" ]
|
||||
echo "\
|
||||
$RED$BOLDUnknown value for MESSAGE_POSITION $YSU__MESSAGE_POSITION
|
||||
Expected value 'before' or 'after'"
|
||||
__ysu__flush_buffer
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue