has_prefix fish util

This commit is contained in:
emilis 2023-01-05 19:34:10 +00:00
parent 8c396b7101
commit 200edc9c96
1 changed files with 17 additions and 0 deletions

17
fish/functions/has_prefix.fish Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env fish
function has_prefix
set -f input_str $argv[2]
set -f match $argv[1]
if test -z $input_str; or test -z $match
log -c red "input[$input_str]/match[$match] empty"
return 1
end
set -f m_len (string length $match)
set -f input_len (string length $input_str)
if test $m_len -gt $input_len
return 1
end
set -f cut_input (string sub -l $m_len $input_str)
return (test "$cut_input" = "$match")
end