printf" %s[n] to edit the n:th element of %s\n"$argv$argv
end
end
else
printf"vared: Expected exactly one argument, got %s.\n\nSynopsis:\n\t"(count$argv)
set_color$FISH_COLOR_COMMAND
printf vared
set_color$FISH_COLOR_NORMAL
printf" VARIABLE\n"
end
end
#
# This function is bound to Alt-L, it is used to list the contents of
# the directory under the cursor
#
function__fish_list_current_token-d"List contents of token under the cursor if it is a directory, otherwise list the contents of the current directory"
setval(eval echo (commandline-t))
iftest-d$val
ls $val
else
setdir(dirname$val)
iftest$dir != . -a-d$dir
ls $dir
else
ls
end
end
end
functionpushd-d"Push directory to stack"
# Comment to avoid set completions
set-gdirstack(command pwd)$dirstack
cd$argv[1]
end
functionpopd-d"Pop dir from stack"
iftest$dirstack[1]
cd$dirstack[1]
else
echo Directory stack is empty...
return1
end
set-edirstack[1]
end
functiondirs-d"Print directory stack"
echo-n(command pwd)" "
foriin$dirstack
echo-n$i" "
end
echo
end
#
# The following functions add support for a directory history
#
functioncd-d"Change directory"
# Skip history in subshells
ifstatus--is-command-substitution
builtin cd $argv
return$status
end
# Avoid set completions
set-- previous(command pwd)
iftest$argv[1]=- ^/dev/null
iftest$__fish_cd_direction= next ^/dev/null
nextd
else
prevd
end
return$status
end
builtin cd $argv[1]
iftest$status=0-a(command pwd) !=$previous
set-gdirprev$dirprev$previous
set-edirnext
set-g__fish_cd_direction prev
end
return$status
end
function__fish_move_last-d"Move the last element of a directory history from src to dest"
setsrc$argv[1]
setdest$argv[2]
setsize_src(count$$src)
iftest$size_src=0
# Cannot make this step
echo"Hit end of history..."
return1
end
# Append current dir to the end of the destination
set-g(echo$dest)$$dest (command pwd)
setssrc$$src
# Change dir to the last entry in the source dir-hist
builtin cd $ssrc[$size_src]
# Keep all but the last from the source dir-hist
set-e(echo$src)[$size_src]
# All ok, return success
return0
end
functionprevd-d"Move back in the directory history"
# Parse arguments
setshow_hist0
settimes1
foriin(seq(count$argv))
switch$argv[$i]
case'-l'
setshow_hist1
continue
case'-*'
echo Uknown option $argv[$i]
return1
case'*'
iftest$argv[$i]-ge0^/dev/null
settimes$argv[$i]
else
echo"The number of positions to skip must be a non-negative integer"
return1
end
continue
end
end
# Traverse history
setcode1
foriin(seq$times)
# Try one step backward
if __fish_move_last dirprev dirnext;
# We consider it a success if we were able to do at least 1 step
# (low expectations are the key to happiness ;)
setcode0
else
break
end
end
# Show history if needed
iftest$show_hist=1
dirh
end
# Set direction for 'cd -'
iftest$code=0^/dev/null
set-g__fish_cd_direction next
end
# All done
return$code
end
functionnextd-d"Move forward in the directory history"
# Parse arguments
setshow_hist0
settimes1
foriin(seq(count$argv))
switch$argv[$i]
case'-l'
setshow_hist1
continue
case'-*'
echo Uknown option $argv[$i]
return1
case'*'
iftest$argv[$i]-ge0^/dev/null
settimes$argv[$i]
else
echo"The number of positions to skip must be a non-negative integer"
return1
end
continue
end
end
# Traverse history
setcode1
foriin(seq$times)
# Try one step backward
if __fish_move_last dirnext dirprev;
# We consider it a success if we were able to do at least 1 step
# (low expectations are the key to happiness ;)
setcode0
else
break
end
end
# Show history if needed
iftest$show_hist=1
dirh
end
# Set direction for 'cd -'
iftest$code=0^/dev/null
set-g__fish_cd_direction prev
end
# All done
return$code
end
functiondirh-d"Print the current directory history (the back- and fwd- lists)"
echo\t$bullet(__bold-h) or (__bold--help) print this message
echo\t$bullet(__bold-a) or (__bold--all) print all of possible definitions of the specified \n\t\ \ names
echo\t$bullet(__bold-f) or (__bold--no-functions) supresses function andbuiltin lookup
echo\t$bullet(__bold-t) or (__bold--type) print a string which is one of alias, keyword, \n\t\ \ function, builtin, or file if name is an alias, shell \n\t\ \ reserved word, function, builtin, or disk file, respectively
echo\t$bullet(__bold-p) or (__bold--path) either return the name of the disk file that would \n\t\ \ be executed if name were specified as a command name, or nothing\n\t\ \ if ‘‘type-t name’’ would not return file
echo\t$bullet(__bold-P) or (__bold--force-path) either return the name of the disk file that \n\t\ \ would be executed if name were specified as a command name, \n\t\ \ or nothing no file with the spacified name could be found \n\t\ \ in the PATH