fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
6d0cd3d9b
master
1function fish_config --description"Launch fish's web based configuration" 2set -l _flag_color_theme 3set -l _flag_no_override 4 5argparse h/help color-theme= no-override --$argv 6or return 7 8if set -q _flag_help 9__fish_print_help fish_config 10return 0 11end 12 13set -l cmd$argv [ 1 ] 14set -e argv[ 1 ] 15 16set -q cmd[ 1 ] 17or set cmd browse 18 19if set -q _flag_color_theme[ 1 ] 20if test $cmd != theme 21or not contains --" $argv [ 1 ] " choose save 22echo >&2 "fish_config: --color-theme: unknown option" 23return 1 24end 25if not contains --$_flag_color_theme dark light unknown 26echo >&2 "fish_config theme: --color-theme argument must be one of 'dark', 'light' or 'unknown', got: ' $_flag_color_theme '" 27return 1 28end 29end 30if set -q _flag_no_override[ 1 ] 31if test $cmd != theme 32or test " $argv [ 1 ] " != choose 33echo >&2 "fish_config: --no-override: unknown option" 34return 1 35end 36end 37 38# The web-based configuration UI 39# Also opened with just `fish_config` or `fish_config browse`. 40if test $cmd = browse 41if set -l python( __fish_anypython ) 42function __fish_config_webconfig -V python -a web_config 43set -lx fish_bin_dir$__fish_bin_dir 44set -lx __fish_terminal_color_theme$fish_terminal_color_theme 45$python $web_config /webconfig.py 46end 47__fish_data_with_directory tools/web_config'.*' __fish_config_webconfig 48__fish_with_status functions --erase __fish_config_webconfig 49 50# If the execution of 'webconfig.py' fails, display python location and return. 51or begin 52echo "Please check if Python has been installed successfully." 53echo "You can find the location of Python by executing the 'command -s $python ' command." 54return 1 55end 56 57else 58echo ( set_color $fish_color_error ) Cannot launch the web configuration tool:( set_color --reset) 59echo ( set_color -o) "fish_config browse" ( set_color --reset) requires Python. 60echo Installing python will fix this, and also enable completions to be 61echo automatically generated from man pages.\n 62echo To change your prompt, use( set_color -o) "fish_config prompt" ( set_color --reset) or create a( set_color -o) "fish_prompt" ( set_color --reset) function. 63echo To list the samples use( set_color -o) "fish_config prompt show" ( set_color --reset) .\n 64 65echo You can tweak your colors by setting the( set_color $fish_color_search_match ) \$ fish_color_\* ( set_color --reset) variables. 66end 67return 0 68end 69 70if not contains --$cmd prompt theme 71echo No such subcommand:$cmd >&2 72return 1 73end 74 75switch $cmd 76case prompt 77# prompt - for prompt switching 78set -l cmd$argv [ 1 ] 79set -e argv[ 1 ] 80 81if contains --$cmd list;and set -q argv[ 1 ] 82echo "Too many arguments" >&2 83return 1 84end 85 86switch $cmd 87case show 88set -l fish( status fish-path) 89for pin ( __fish_config_list_prompts $argv ) 90set -l promptname( string replace -r'.*/([^/]*).fish$' '$1' $p ) 91echo -s( set_color --underline) $promptname ( set_color --reset) 92$fish -c' 93functions -e fish_right_prompt 94__fish_config_with_file $argv[1] source 95false 96fish_prompt 97echo (set_color --reset) 98if functions -q fish_right_prompt 99echo right prompt: (false; fish_right_prompt) 100end' $p 101echo 102end 103case list'' 104__fish_config_list_prompts | 105string replace -r'.*/([^/]*).fish$' '$1' 106return 107case choose 108if set -q argv[ 2 ] 109echo "Too many arguments" >&2 110return 1 111end 112if not set -q argv[ 1 ] 113echo "Too few arguments" >&2 114return 1 115end 116 117set -l prompt_path( __fish_config_list_prompts $argv [ 1 ]) 118if not set -q prompt_path[ 1 ] 119echo "No such prompt: ' $argv [ 1 ] '" >&2 120return 1 121end 122__fish_config_prompt_reset 123__fish_config_with_file $prompt_path source 124if not functions -q fish_mode_prompt 125status get-file functions/fish_mode_prompt.fish| source 126end 127case save 128if begin 129read -P"Overwrite prompt? [y/N]" -l yesno 130not string match -riq'y(es)?' --$yesno 131end 132echo Not overwriting 133return 1 134end 135echo Overwriting 136__fish_backup_config_files functions/{ fish_prompt, fish_right_prompt, fish_mode_prompt} .fish 137 138if set -q argv[ 1 ] 139set -l prompt_path( __fish_config_list_prompts $argv [ 1 ]) 140if not set -q prompt_path[ 1 ] 141echo "No such prompt: ' $argv [ 1 ] '" >&2 142return 1 143end 144__fish_config_prompt_reset 145__fish_config_with_file $prompt_path source 146end 147 148funcsave fish_prompt 149or return 150 151for funcin fish_right_prompt fish_mode_prompt 152if functions -q$func 153funcsave $func 154else 155rm -f$__fish_config_dir /functions/$func .fish 156end 157end 158if not functions -q fish_mode_prompt 159status get-file functions/fish_mode_prompt.fish| source 160end 161return 162end 163 164return 0 165case theme 166# Selecting themes 167set -l cmd$argv [ 1 ] 168set -e argv[ 1 ] 169 170if contains --$cmd list;and set -q argv[ 1 ] 171echo "Too many arguments" >&2 172return 1 173end 174 175switch $cmd 176case list'' 177__fish_theme_names 178return 179case demo 180echo -ns( set_color $fish_color_command || set_color $fish_color_normal ) /bright/vixens 181echo -ns( set_color --reset) ' ' 182echo -ns( set_color $fish_color_param || set_color $fish_color_normal ) jump 183echo -ns( set_color --reset) ' ' 184echo -ns( set_color $fish_color_redirection || set_color $fish_color_normal ) '|' 185echo -ns( set_color --reset) ' ' 186echo -ns( set_color $fish_color_quote || set_color $fish_color_normal ) '"fowl"' 187echo -ns( set_color --reset) ' ' 188echo -ns( set_color $fish_color_redirection || set_color $fish_color_normal ) '> quack' 189echo -ns( set_color --reset) ' ' 190echo -ns( set_color $fish_color_end || set_color $fish_color_normal ) '&' 191set_color --reset 192echo -s( set_color $fish_color_comment || set_color $fish_color_normal ) ' # This is a comment' 193set_color --reset 194echo -ns( set_color $fish_color_command || set_color $fish_color_normal ) echo 195echo -ns( set_color --reset) ' ' 196echo -s( set_color $fish_color_error || set_color $fish_color_normal ) "'" ( set_color $fish_color_quote || set_color $fish_color_normal ) "Errors are the portal to discovery" 197set_color --reset 198echo -ns( set_color $fish_color_command || set_color $fish_color_normal ) Th 199set_color --reset 200set_color $fish_color_autosuggestion || set_color $fish_color_normal 201echo is an autosuggestion 202echo 203case show 204echo -s( set_color --reset;set_color --underline) Current( set_color --reset) 205fish_config theme demo 206__fish_theme_for_each __fish_config_theme_demo$argv 207case choose save 208__fish_config_theme_choose $cmd $argv --color-theme=$_flag_color_theme $_flag_no_override 209return 210case dump 211if set -q argv[ 1 ] 212echo "Too many arguments" >&2 213return 1 214end 215# Write some of the current theme in .theme format, to stdout. 216for varnamein ( __fish_theme_variables ) 217__fish_posix_quote $varname $$varname 218echo 219end 220case '*' 221echo "No such command: $cmd " >&2 222return 1 223end 224end 225end 226 227function __fish_config_list_prompts 228set -lx dir 229set -l prompt_paths( __fish_config_files prompts .fish$argv ) 230if [ ( count $argv ) = 1 ] && set -q prompt_paths[ 2 ] 231echo >&2 "fish_config: internal error: multiple prompts matching ' $argv ' ??" 232set --erase prompt_paths[ 2..] 233end 234string join\n --$prompt_paths 235end 236 237function __fish_config_theme_choose_bad_color_theme -a theme_name desired_color_theme source 238echo >&2 "fish_config theme choose: failed to find '[ $desired_color_theme ]' section (implied by $source ) in ' $theme_name ' theme" 239end 240 241function __fish_config_theme_choose 242set -l cmd$argv [ 1 ] 243set -e argv[ 1 ] 244set -l _flag_color_theme 245set -l _flag_no_override 246argparse color-theme= no-override --$argv 247or return 248if set -q argv[ 2 ] 249echo "Too many arguments" >&2 250return 1 251end 252# The name of the theme to save *from* is optional for `fish_config theme save` 253if not set -q argv[ 1 ] && contains --$cmd choose 254echo "Too few arguments" >&2 255return 1 256end 257 258set -l scope -g 259 260if test $cmd = save 261read -P"Overwrite your current theme? [y/N] " -l yesno 262if not string match -riq'y(es)?' --$yesno 263echo Not overwriting>&2 264return 1 265end 266set scope -U 267end 268 269set -l theme_name$argv [ 1 ] 270set -l desired_color_theme$_flag_color_theme 271 272# Persist the currently loaded/themed variables (in case of `theme save`). 273if not set -q theme_name[ 1 ] 274# We're persisting whatever current colors are loaded (maybe in the global scope) 275# to the universal scope, without overriding them from a theme file. 276# Like above, make sure to erase from other scopes first and ensure known color 277# variables are defined, even if empty. 278# This branch is only reachable in the case of `theme save` so $scope is always `-U`. 279for colorin ( __fish_theme_variables ) 280# Cache the value from whatever scope currently defines it 281set -l value$$color 282set -eg$color 283set -U$color $value 284end 285return 0 286end 287 288set -l color_theme 289__fish_config_theme_canonicalize 290set -l theme_data( __fish_theme_cat $theme_name ) 291or return 292set -l color_themes dark light unknown 293set -l theme_is_color_theme_aware false 294for ctin $color_themes 295if contains --[ $ct ] $theme_data 296set theme_is_color_theme_aware true 297end 298end 299set -l need_hook true 300if not $theme_is_color_theme_aware || set -q desired_color_theme[ 1 ] || set -q color_theme[ 1 ] || test $cmd = save 301set need_hook false 302end 303function __fish_apply_theme ( $need_hook && printf %s\n --on-variable fish_terminal_color_theme) \ 304 -V color_themes -V theme_name -V color_theme -V theme_data -V theme_is_color_theme_aware\ 305 -V desired_color_theme -V scope 306if set -q __fish_color_theme[ 1 ] 307set desired_color_theme$__fish_color_theme 308end 309 310if set -q color_theme[ 1 ] && not set -q desired_color_theme[ 1 ] 311set desired_color_theme$color_theme 312end 313set -l override( test -n " $__fish_override " && builtin echo true|| builtin echo false) 314 315if $theme_is_color_theme_aware 316if set -q desired_color_theme[ 1 ] 317if not contains --"[ $desired_color_theme ]" $theme_data 318__fish_config_theme_choose_bad_color_theme $theme_name " $desired_color_theme " --color-theme=$desired_color_theme 319return 1 320end 321else 322set desired_color_theme$fish_terminal_color_theme 323if not set -q desired_color_theme[ 1 ] 324if test $scope = -U 325echo >&2 "fish_config theme save: error: \$fish_terminal_color_theme not yet initialized" 326return 1 327end 328else if not contains --"[ $desired_color_theme ]" $theme_data 329__fish_config_theme_choose_bad_color_theme $theme_name " $desired_color_theme " \$ fish_terminal_color_theme =$desired_color_theme 330echo >&2 "fish_config theme choose: hint: if your terminal does not report colors, pass --color-theme=light or --color-theme=dark when using color-theme-aware themes" 331return 1 332end 333end 334else 335if set -q desired_color_theme[ 1 ] 336and test " $desired_color_theme " != unknown 337and not contains --"[ $desired_color_theme ]" $theme_data 338__fish_config_theme_choose_bad_color_theme $theme_name " $desired_color_theme " --color-theme=$desired_color_theme 339return 1 340end 341end 342 343set -l color_theme 344string match -re --( __fish_theme_variable_filter ) '|^\[.*\]$' $theme_data | 345while read -lat toks 346if $theme_is_color_theme_aware && set -q desired_color_theme[ 1 ] 347for ctin $color_themes 348if test " $toks " = [ $ct ] 349set color_theme$ct 350break 351end 352end 353if test " $color_theme " != $desired_color_theme 354continue 355end 356end 357set -l varname$toks [ 1 ] 358string match -q'[*' --$varname 359and continue 360# If we're supposed to set universally, remove any shadowing globals 361# so the change takes effect immediately (and there's no warning). 362if test $scope = -U ;and set -qg$varname 363set -eg$varname 364end 365if $override || not set -q$varname || string match -rq --'--theme=.*' $$varname 366set $scope $toks [ 1 ] ( 367if not $theme_is_color_theme_aware || set -q desired_color_theme[ 1 ] 368string join\n --$toks [ 2 .. ] 369end 370) ( test $scope != -U && echo --theme=$theme_name ) 371end 372end 373if $override 374for cin ( __fish_theme_variables ) 375string match -rq --"^--theme=(?!$ ( string escape --style=regex -- $theme_name ) \$).*" $$c 376or continue 377# Erase conflicting global variables so we don't get a warning and 378# so changes are observed immediately. 379set -eg$c 380set $scope $c 381end 382end 383end 384if not $need_hook || test -n " $fish_terminal_color_theme " || 385{ 386$theme_is_color_theme_aware && test -z " $fish_terminal_color_theme " 387} 388if not set -q _flag_no_override[ 1 ] 389set -fx __fish_override true 390end 391__fish_apply_theme 392end 393end 394 395function __fish_config_theme_canonicalize --no-scope-shadowing 396# theme_name 397# color_theme 398if path is ( __fish_theme_dir )/ $theme_name .theme 399return 400end 401switch $theme_name 402case 'fish default' 403set theme_name default 404case 'ayu Dark' 'ayu Light' 'ayu Mirage' \ 405'Base16 Default Dark' 'Base16 Default Light' 'Base16 Eighties' \ 406'Bay Cruise' Dracula Fairground 'Just a Touch' Lava \ 407'Mono Lace' 'Mono Smoke' \ 408None Nord 'Old School' Seaweed 'Snow Day' \ 409'Solarized Dark' 'Solarized Light' \ 410'Tomorrow Night Bright' 'Tomorrow Night' Tomorrow 411if test $theme_name = Tomorrow 412set color_theme light 413end 414set theme_name ( string lower ( string replace -a " " "-" $theme_name )) 415end 416switch $theme_name 417case \ 418ayu-dark ayu-light \ 419base16-default-dark base16-default-light \ 420solarized-dark solarized-light 421string match -rq -- '^(?<theme_name>.*)-(?<color_theme>dark|light)$' $theme_name 422case tomorrow-night 423set theme_name tomorrow 424set color_theme dark 425end 426end 427 428function __fish_config_theme_demo 429argparse name= data=+ color-themes=+ -- $argv 430or return 431set -l name $_flag_name 432set -l color_themes $_flag_color_themes 433# Use a new, --no-config, fish to display the theme. 434set -l fish ( status fish-path) 435$fish --no-config -c ' 436set -l name $argv[1] 437for color_theme in $argv[2..] 438echo -s (set_color --reset; set_color --underline) "$name" \ 439" ($color_theme color theme)" (set_color --reset) 440fish_config theme choose $name --color-theme=$color_theme 441fish_config theme demo 442end 443' $name $color_themes 444end 445 446function __fish_config_prompt_reset 447# Set the functions to empty so we empty the file 448# if necessary. 449function fish_prompt 450end 451for func in fish_right_prompt fish_mode_prompt 452if functions -q $func 453functions --erase $func 454end 455end 456end