chore: separating fishtool from main fish config
This commit is contained in:
62
functions/fishtools.fish
Normal file
62
functions/fishtools.fish
Normal file
@@ -0,0 +1,62 @@
|
||||
function fishtools-startswith
|
||||
set len1 (string length $argv[1])
|
||||
set len2 (string length $argv[2])
|
||||
if test $len1 -lt $len2
|
||||
set tmp (string sub -l $len1 $argv[2])
|
||||
if test $tmp = $argv[1]
|
||||
return 0
|
||||
end
|
||||
else
|
||||
set tmp (string sub -l $len2 $argv[1])
|
||||
if test $tmp = $argv[2]
|
||||
return 0
|
||||
end
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
function fishtools-in-list
|
||||
if test (count $argv) -ge 2
|
||||
for i in $argv[2..-1]
|
||||
if test "$i" = "$argv[1]"
|
||||
return 0
|
||||
end
|
||||
end
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
function fishtools-enable-rust
|
||||
if test -e $HOME/.cargo/bin
|
||||
set real (realpath $HOME/.cargo/bin)
|
||||
|
||||
if not fishtools in $real $PATH
|
||||
set -gx PATH $real $PATH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function fishtools-enable
|
||||
for i in $argv
|
||||
switch $i
|
||||
case rust
|
||||
fishtools-enable-rust
|
||||
case '*'
|
||||
echo "unsupported " $argv[1]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function fishtools
|
||||
switch $argv[1]
|
||||
case startswith
|
||||
fishtools-startswith $argv[2..-1]
|
||||
case in
|
||||
fishtools-in-list $argv[2..-1]
|
||||
case enable
|
||||
fishtools-enable $argv[2..-1]
|
||||
case '*'
|
||||
echo "unknown sub-command:" $argv
|
||||
return 1
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user