On Thu, 10 Jan 2019, Simon Lees wrote:
> I do some probably "unusual" things with fish shell scripts, some of
> these have broken in fish 3.0, i'm going to start by describing the
> problem because i'm interested in any solution even if its significantly
> different to what I was doing before.
>
> For my prompt / greeting etc I prefer to use terminal escape sequences
> rather then fish's set_color methods, this is because it properly
> follows changes to my terminals palette which I do regularly depending
> on which machine the terminal session is in.
If you use named colours (ie the output of `set_color --print-colors`),
this will follow the terminal palette, in case that helps to simplify
things.
> To make this process more sane I store each escape sequence in an
> environment variable, and to make that less painful each environment
> variable is loaded from a file, some sample lines are below but you can
> see the full file here
> https://github.com/simotek/tackle/blob/simotek-theme/themes/simotek/simotek_theme_colors.en
>
> (note I also load a bunch of other env vars from other files)
>
> smtk_clr_black=\e[0;30m# Black
> smtk_clr_red=\e[0;31m# Red
> smtk_clr_green=\e[0;32m# Green
> smtk_clr_yellow=\e[0;33m# Yellow
>
> To make this more fun I sometimes also load environment variables that
> contain environment variables that need to be expanded such as
>
> PATH=$PATH $HOME/.local/bin $HOME/src/Scripts /sbin /usr/sbin
> # Fun test Enlightenment exports the variable PANTS as ON
> SHIRT=$PANTS# Inline comment test
>
> Taken from https://github.com/simotek/tackle/blob/simotek-theme/default.env
>
> The code to load such variables used to look like this (note PATH is
> handled as a special case differently)
>
> # need to expand $split[2] twice so that any vars stored in the file
> get expanded
> set -l TMP "echo -e \"$split[2]\""
> printf "%s" (eval $TMP) | read -gx $split[1]
>
>
> Taken from line 118 of
> https://github.com/simotek/tacklebox/blob/feature-env-loader-theme/tacklebox.fish
> the echo -e substitutes in the terminal escape characters and the printf
> expands the environment variables.
>
> This now fails with the following:
>
> eval $TMP
> ^
> in command substitution
> called on line 223 of file ~/src/config/tacklebox/tacklebox.fish
> in function “__tacklebox_load_env_file”
> called on line 334 of file ~/src/config/tacklebox/tacklebox.fish
> in function “__tacklebox_load_env_files_in_dir”
> called on line 100 of file ~/src/config/tacklebox/tacklebox.fish
> in function “__tacklebox_load_theme”
> called on line 209 of file ~/src/config/tacklebox/tacklebox.fish
> with parameter list “simotek”
> from sourcing file ~/src/config/tacklebox/tacklebox.fish
> called on line 9 of file ~/.config/fish/config.fish
> from sourcing file ~/.config/fish/config.fish
> called during startup
Can you give an example of a variable that fails?
I tried:
set split (string split -m 1 = 'smtk_clr_black=\e[0;30m')
set -l TMP "echo -e \"$split[2]\""
printf "%s" (eval $TMP) | read -gx $split[1]
and smtk_clr_black seems to be set to the expected value. Same with
"SOMEVAR=$HOME".
This whole thing is pretty gnarly; I've spent about half an hour trying to
understand it.
> Removing the eval so I have printf "%s ($TMP)" gives the following:
>
> echo -e "\e[0;40m": command not found
> ~/src/config/tacklebox/tacklebox.fish (line 1):
> $TMP
> ^
> in command substitution
> called on line 223 of file ~/src/config/tacklebox/tacklebox.fish
> in function “__tacklebox_load_env_file”
> called on line 12 of file
> ~/src/config/tackle/themes/simotek/fish_right_prompt.fish
> in function “fish_right_prompt”
> called on standard input
> in command substitution
> called on standard input
Yep, that's because you're trying to run that whole variable as a command
in the substitution. You can remove one set of double quotes from the `set
-l TMP` line, but that won't expand the variables like you want any more.
I think Fabian (@faho) wrote an `expand` builtin at one point, which would
solve the need for `eval`, but I don't think it ever got merged.
David Adam
zanc...@ucc.gu.uwa.edu.au
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users