Last active
April 18, 2018 02:30
-
-
Save sh78/e6ec1f76e639ad95992b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myfunc --description "Basic Function. Args Are Built In" | |
echo $argv | |
echo $argv[1] $argv[2] # no zero indices in the ocean... | |
end | |
# └> myfunc one two three | |
# one two three | |
# one two two | |
function myfunc --description "Basic Function With Variables" | |
set myvar "this is mine" | |
set yourvar $argv | |
echo $myvar | |
echo these are yours: $yourvar | |
end | |
# └> myfunc one two | |
# this is mine | |
# these are yours: one two | |
function myfunc --description "Test Number Of Arguments" | |
set args (count $argv) | |
if math "$args < 1" > /dev/null | |
echo "Please enter some arguments..." | |
else if math "$args > 0" | |
# do stuff here | |
else | |
# twilight zone | |
end | |
end | |
# └> myfunc | |
# Please enter some arguments... | |
function myfunc --description "String Splitting And Comparison" | |
set myvar (history | head -n 1 | awk '{ print $1 }') # most recent line of command history | |
if test $myvar = "sudo" | |
echo Be careful with that sudo business | |
else | |
echo Playing it safe | |
end | |
end | |
# └> sudo ls notes/ | |
# └> myfunc | |
# Be careful with that sudo business | |
# └> myfunc | |
# Playing it safe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment