aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2005-09-24 11:30:16 +1000
committerGravatar axel <axel@liljencrantz.se>2005-09-24 11:30:16 +1000
commit5a7a14003f7d66d36815e7ae60470db288433175 (patch)
tree1c77bd0592236b6f082ad2bae8b7b58f67721e8d
parent3e0e50fbf325b53f29b17deda9eecd8c4f016814 (diff)
Update for type function
darcs-hash:20050924013016-ac50b-d153454213661a003b54306f9ee32caf6c390505.gz
-rw-r--r--Makefile.in2
-rw-r--r--doc_src/type.txt20
-rw-r--r--init/fish_function.fish177
3 files changed, 117 insertions, 82 deletions
diff --git a/Makefile.in b/Makefile.in
index 956d618c..e763cbb1 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -103,7 +103,7 @@ CMD_DOC_SRC := doc_src/count.txt doc_src/dirh.txt doc_src/dirs.txt \
doc_src/fishd.txt doc_src/help.txt doc_src/mimedb.txt \
doc_src/nextd.txt doc_src/open.txt doc_src/popd.txt \
doc_src/prevd.txt doc_src/pushd.txt doc_src/set_color.txt \
- doc_src/tokenize.txt
+ doc_src/tokenize.txt doc_src/type.txt
#
# Files generated by running doxygen on the files in $(CMD_DOC_SRC)
diff --git a/doc_src/type.txt b/doc_src/type.txt
new file mode 100644
index 00000000..424e2874
--- /dev/null
+++ b/doc_src/type.txt
@@ -0,0 +1,20 @@
+
+\section type type - Indicate how a name would be interpreted if used as a command name
+
+\subsection type-synopsis Synopsis
+ <tt>type [OPTIONS] name [name ...]</tt>
+
+\subsection type-description Description
+
+With no options, indicate how each name would be interpreted if used as a command name.
+
+- \c -h or \c --help print this message
+- \c -a or \c --all print all of possible definitions of the specified names
+- \c -f or \c --no-functions supresses function and builtin lookup
+- \c -t or \c --type print a string which is one of alias, keyword, function, builtin, or file if name is an alias, shell reserved word, function, builtin, or disk file, respectively
+- \c -p or \c --path either return the name of the disk file that would be executed if name were specified as a command name, or nothing if ‘‘type -t name’’ would not return file
+- \c -P or \c --force-path either return the name of the disk file that would be executed if name were specified as a command name, or nothing no file with the spacified name could be found in the PATH
+
+\subsection type-example Example
+
+<tt>type fg</tt> outputs the string 'fg is a shell builtin'.
diff --git a/init/fish_function.fish b/init/fish_function.fish
index bbed4e1c..9aa425c8 100644
--- a/init/fish_function.fish
+++ b/init/fish_function.fish
@@ -242,7 +242,7 @@ function vared -d "Edit variable value"
switch $argv
case '-h' '--h' '--he' '--hel' '--help'
- printf "Synopsis\n\t%svared%s VARIABLE\n\n" (set_color $FISH_COLOR_COMMAND) (set_color $FISH_COLOR_NORMAL)
+ printf "Synopsis\n\t%svared%s VARIABLE\n\n" (set_color $fish_color_command) (set_color normal)
printf "\tInteractively edit the value of an environment variable\n\n"
case '-*'
@@ -528,11 +528,41 @@ function dirh -d "Print the current directory history (the back- and fwd- lists)
echo
end
+function __bold -d "Print argument in bold"
+ set_color --bold
+ printf "%s" $argv[1]
+ set_color normal
+end
+
+function __type_help -d "Help for the type shellscript function"
+
+echo \ttype type - Indicate how a name would be interpreted if used as a command name
+echo (__bold Synopsis)
+echo \t(set_color $fish_color_command)type(set_color normal) [OPTIONS] name [name ...]
+echo
+echo (__bold Description)
+echo
+echo \tWith no options, indicate how each name would be interpreted if used as a command name.
+echo
+echo \t\* (__bold -h) or (__bold --help) print this message
+echo \t\* (__bold -a) or (__bold --all) print all of possible definitions of the specified names
+echo \t\* (__bold -f) or (__bold --no-functions) supresses function and builtin lookup
+echo \t\* (__bold -t) or (__bold --type) print a string which is one of alias, keyword, function, builtin, or file if name is an alias, shell reserved word, function, builtin, or disk file, respectively
+echo \t\* (__bold -p) or (__bold --path) either return the name of the disk file that would be executed if name were specified as a command name, or nothing if ‘‘type -t name’’ would not return file
+echo \t\* (__bold -P) or (__bold --force-path) either return the name of the disk file that would be executed if name were specified as a command name, or nothing no file with the spacified name could be found in the PATH
+echo
+echo (__bold Example)
+echo
+echo \t\'(set_color $fish_color_command)type(set_color normal) fg\' outputs the string \'fg is a shell builtin\'.
+echo
+
+end
function type -d "Print the type of a command"
- set status 0
+ set status 1
set mode normal
+ set selection all
for i in $argv
switch $i
@@ -542,8 +572,18 @@ function type -d "Print the type of a command"
case -p --p --pa --pat --path
set mode path
+ case -P --f --fo --for --forc --force --force- --force-p --force-pa --force-pat --force-path
+ set mode path
+ set selection files
+
case -a --a --al --all
- set mode all
+ set selection multi
+
+ case -f --n --no --no- --no-f --no-fu --no-fun --no-func --no-funct --no-functi --no-functio --no-function --no-functions
+ set selection files
+
+ case -h --h --he --hel --help
+ __type_help
case --
break
@@ -554,105 +594,80 @@ function type -d "Print the type of a command"
end
end
- switch $mode
-
- case normal
- for i in $argv
+ for i in $argv
+
+ switch $i
+ case '-*'
+ continue
+ end
- switch $i
- case '-*'
- continue;
- end
+ # Found will be set to 1 if a match is found
+ set found 0
- if contains -- $i (functions -n)
- echo $i is a function with definition
- functions $i
- continue
- end
+ if test $selection != files
- if contains -- $i (builtin -n)
- echo $i is a shell builtin
- continue
- end
+ if contains -- $i (functions -n)
+ set status 0
+ set found 1
+ switch $mode
+ case normal
+ echo $i is a function with definition
+ functions $i
- if which $i ^/dev/null >/dev/null
- echo $i is (which $i)
- continue
- end
- echo type: $i: not found
- set status 1
- end
+ case type
+ echo function
- case path
- for i in $argv
+ case path
+ echo
- switch $i
- case '-*'
- continue;
end
-
- if which $i ^/dev/null >/dev/null
- echo $i is (which $i)
+ if test $selection != multi
continue
end
- set status 1
end
- case all
- for i in $argv
- set found ""
- switch $i
- case '-*'
- continue;
- end
-
- if contains -- $i (functions -n)
- echo $i is a function with definition
- functions $i
- set found 1
- end
+ if contains -- $i (builtin -n)
+ set status 0
+ set found 1
+ switch $mode
+ case normal
+ echo $i is a builtin
- if contains -- $i (builtin -n)
- echo $i is a shell builtin
- set found 1
- end
+ case type
+ echo builtin
- if which $i ^/dev/null >/dev/null
- echo $i is (which $i)
- set found 1
+ case path
+ echo
end
-
- if test -z $found
- echo type: $i: not found
- set status 1
+ if test $selection != multi
+ continue
end
end
-
- case type
- for i in $argv
-
- switch $i
- case '-*'
- continue;
- end
+ end
- if contains -- $i (functions -n)
- echo function
- continue
- end
+ if which $i ^/dev/null >/dev/null
+ set status 0
+ set found 1
+ switch $mode
+ case normal
+ echo $i is (which $i)
- if contains -- $i (builtin -n)
- echo builtin
- continue
- end
+ case type
+ echo file
- if which $i ^/dev/null >/dev/null
- echo file
- continue
- end
- set status 1
+ case path
+ which $i
end
+ if test $selection != multi
+ continue
+ end
+ end
+
+ if test $found = 0
+ echo type: $i: not found
+ end
+
end
return $status