aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/functions/type.fish
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-02-17 20:13:39 +1000
committerGravatar axel <axel@liljencrantz.se>2006-02-17 20:13:39 +1000
commit343cafef346543282b5b6e825bc8f9dd10028a48 (patch)
tree1bcf221ecb525c7aeadc8325e7b780d3656e544b /share/functions/type.fish
parent95a01f3c8f15034433ffce368d8f2d13d925139c (diff)
Redo installation file structure, move lots of things to $PREFIX/share/fish
darcs-hash:20060217101339-ac50b-d93d2c620a4b7f75f05ff461a6edbee001da7613.gz
Diffstat (limited to 'share/functions/type.fish')
-rw-r--r--share/functions/type.fish134
1 files changed, 134 insertions, 0 deletions
diff --git a/share/functions/type.fish b/share/functions/type.fish
new file mode 100644
index 00000000..bb5c75e0
--- /dev/null
+++ b/share/functions/type.fish
@@ -0,0 +1,134 @@
+
+function type -d (_ "Print the type of a command")
+
+ # Initialize
+ set -l status 1
+ set -l mode normal
+ set -l selection all
+
+ #
+ # Get options
+ #
+ set -l shortopt -o tpPafh
+ set -l longopt
+ if not getopt -T >/dev/null
+ set longopt -l type,path,force-path,all,no-functions,help
+ end
+
+ if not getopt -n type -Q $shortopt $longopt -- $argv
+ return 1
+ end
+
+ set -l tmp (getopt $shortopt $longopt -- $argv)
+
+ set -l opt
+ eval set opt $tmp
+
+ for i in $opt
+ switch $i
+ case -t --type
+ set mode type
+
+ case -p --path
+ set mode path
+
+ case -P --force-path
+ set mode path
+ set selection files
+
+ case -a --all
+ set selection multi
+
+ case -f --no-functions
+ set selection files
+
+ case -h --help
+ help type
+ return 0
+
+ case --
+ break
+
+ end
+ end
+
+ # Check all possible types for the remaining arguments
+ for i in $argv
+
+ switch $i
+ case '-*'
+ continue
+ end
+
+ # Found will be set to 1 if a match is found
+ set found 0
+
+ if test $selection != files
+
+ if contains -- $i (functions -na)
+ set status 0
+ set found 1
+ switch $mode
+ case normal
+ printf (_ '%s is a function with definition\n') $i
+ functions $i
+
+ case type
+ printf (_ 'function\n')
+
+ case path
+ echo
+
+ end
+ if test $selection != multi
+ continue
+ end
+ end
+
+ if contains -- $i (builtin -n)
+ set status 0
+ set found 1
+ switch $mode
+ case normal
+ printf (_ '%s is a builtin\n') $i
+
+ case type
+ printf (_ 'builtin\n')
+
+ case path
+ echo
+ end
+ if test $selection != multi
+ continue
+ end
+ end
+
+ end
+
+ if which $i ^/dev/null >/dev/null
+ set status 0
+ set found 1
+ switch $mode
+ case normal
+ printf (_ '%s is %s\n') $i (which $i)
+
+ case type
+ printf (_ 'file\n')
+
+ case path
+ which $i
+ end
+ if test $selection != multi
+ continue
+ end
+ end
+
+ if test $found = 0
+ printf (_ "%s: Could not find '%s'") type $i
+ end
+
+ end
+
+ return $status
+end
+