How to do whilespace-insensitive string compare in fish

From razwiki
Revision as of 11:20, 6 December 2021 by Razzi (talk | contribs) (→‎See also)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The problem:

test "a b " = "a b"

exits with 1; this comes up with `fish_postexec`:

if test "$argv" = "$EDITOR ~/.profile"
->
test vim ~/.profile  = vim ~/.profile

which itself happens because tab completion adds a space at the end.

Solution:

test (echo "$argv" | string trim) = "$EDITOR ~/.profile"

See also

How to automatically source ~/.profile after editing it in fish shell