mirror of
https://github.com/oh-my-fish/oh-my-fish.git
synced 2024-12-05 08:30:50 +08:00
2542929eb9
+ msg.util.get.color.fish + msg.util.random.color.fish + msg.util.set.color.fish + msg.util.str.get.fish + msg.util.str.has.fish
18 lines
537 B
Fish
18 lines
537 B
Fish
# Extract string between left and right separators of variable length.
|
|
# @params <left-sep> [<right-sep>] <string>
|
|
function msg.util.str.get
|
|
set -l left $argv[1]
|
|
set -l right $argv[1]
|
|
set -l string $argv[2]
|
|
|
|
if [ (count $argv) -gt 2 ]
|
|
set right $argv[2]
|
|
set string $argv[3]
|
|
end
|
|
|
|
set -l len (printf $left | awk '{print length}')
|
|
# Match between outermost left / right separators.
|
|
printf $string | sed "s/[^\\$left]*\(\\$left.*\\$right\)*/\1/g" | \
|
|
sed "s/^.\{$len\}\(.*\).\{$len\}\$/\1/"
|
|
end
|