mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-11 15:37:24 +00:00
Move a few more shellscript functions to their own files
darcs-hash:20060212131421-ac50b-861f8941af76cf9a1e6fb7da2ac7f33795fab272.gz
This commit is contained in:
parent
3b03bd6a10
commit
a2cd8c8a8d
11 changed files with 145 additions and 70 deletions
|
@ -4,76 +4,6 @@
|
|||
# function is used by the default prompt command.
|
||||
#
|
||||
|
||||
if test (uname) = Darwin
|
||||
function prompt_pwd -d "Print the current working directory, shortend to fit the prompt"
|
||||
if test "$PWD" != "$HOME"
|
||||
printf "%s" (echo $PWD|sed -e 's|/private||' -e "s|^$HOME|~|" -e 's-/\([^/]\)\([^/]*\)-/\1-g')
|
||||
echo $PWD|sed -e 's-.*/[^/]\([^/]*$\)-\1-'
|
||||
else
|
||||
echo '~'
|
||||
end
|
||||
end
|
||||
else
|
||||
function prompt_pwd -d "Print the current working directory, shortend to fit the prompt"
|
||||
if test "$PWD" != "$HOME"
|
||||
printf "%s" (echo $PWD|sed -e "s|^$HOME|~|" -e 's-/\([^/]\)\([^/]*\)-/\1-g')
|
||||
echo $PWD|sed -e 's-.*/[^/]\([^/]*$\)-\1-'
|
||||
else
|
||||
echo '~'
|
||||
end
|
||||
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"
|
||||
set val (eval echo (commandline -t))
|
||||
if test -d $val
|
||||
ls $val
|
||||
else
|
||||
set dir (dirname $val)
|
||||
if test $dir != . -a -d $dir
|
||||
ls $dir
|
||||
else
|
||||
ls
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function pushd -d "Push directory to stack"
|
||||
# Comment to avoid set completions
|
||||
set -g dirstack (command pwd) $dirstack
|
||||
cd $argv[1]
|
||||
end
|
||||
|
||||
|
||||
function popd -d "Pop dir from stack"
|
||||
if test $dirstack[1]
|
||||
cd $dirstack[1]
|
||||
else
|
||||
printf (_ "%s: Directory stack is empty...") popd
|
||||
return 1
|
||||
end
|
||||
|
||||
set -e dirstack[1]
|
||||
|
||||
end
|
||||
|
||||
|
||||
function dirs -d "Print directory stack"
|
||||
echo -n (command pwd)" "
|
||||
for i in $dirstack
|
||||
echo -n $i" "
|
||||
end
|
||||
echo
|
||||
end
|
||||
|
||||
|
||||
function prevd-or-backward-word --key-binding
|
||||
if test -z (commandline)
|
||||
prevd
|
||||
|
|
8
init/functions/__fish_complete_pids.fish
Normal file
8
init/functions/__fish_complete_pids.fish
Normal file
|
@ -0,0 +1,8 @@
|
|||
function __fish_complete_pids -d "Print a list of process identifiers along with brief descriptions"
|
||||
# This may be a bit slower, but it's nice - having the tty displayed is really handy
|
||||
ps --no-heading -o pid,comm,tty --ppid %self -N | sed -r 's/ *([0-9]+) +([^ ].*[^ ]|[^ ]) +([^ ]+)$/\1\t\2 [\3]/' ^/dev/null
|
||||
|
||||
# If the above is too slow, this is faster but a little less useful
|
||||
# pgrep -l -v -P %self | sed 's/ /\t/'
|
||||
end
|
||||
|
15
init/functions/__fish_is_first_token.fish
Normal file
15
init/functions/__fish_is_first_token.fish
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
function __fish_is_first_token -d 'Test if no non-switch argument has been specified yet'
|
||||
set -- cmd (commandline -poc)
|
||||
set -e -- cmd[1]
|
||||
for i in $cmd
|
||||
switch $i
|
||||
case '-*'
|
||||
|
||||
case '*'
|
||||
return 1;
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
20
init/functions/__fish_list_current_token.fish
Normal file
20
init/functions/__fish_list_current_token.fish
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
#
|
||||
# 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"
|
||||
set val (eval echo (commandline -t))
|
||||
if test -d $val
|
||||
ls $val
|
||||
else
|
||||
set dir (dirname $val)
|
||||
if test $dir != . -a -d $dir
|
||||
ls $dir
|
||||
else
|
||||
ls
|
||||
end
|
||||
end
|
||||
end
|
||||
|
15
init/functions/__fish_no_arguments.fish
Normal file
15
init/functions/__fish_no_arguments.fish
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
function __fish_no_arguments -d "Internal fish function"
|
||||
set -l cmd (commandline -poc) (commandline -tc)
|
||||
set -e cmd[1]
|
||||
for i in $cmd
|
||||
switch $i
|
||||
case '-*'
|
||||
|
||||
case '*'
|
||||
return 1
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
16
init/functions/__fish_print_hostnames.fish
Normal file
16
init/functions/__fish_print_hostnames.fish
Normal file
|
@ -0,0 +1,16 @@
|
|||
|
||||
function __fish_print_hostnames -d "Print a list of known hostnames"
|
||||
|
||||
# Print all hosts from /etc/hosts
|
||||
if test -f /etc/hosts
|
||||
sed </etc/hosts -e 's/[0-9.]*\( \|\t\)*\(.*\)/\2/'|sed -e 's/\#.*//'|tr \t \n |grep -v '^$'
|
||||
end
|
||||
# Print nfs servers from /etc/fstab
|
||||
if test -f /etc/fstab
|
||||
grep </etc/fstab "^\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\|[a-zA-Z.]*\):"|cut -d : -f 1
|
||||
end
|
||||
|
||||
# Print hosts with known ssh keys
|
||||
cat ~/.ssh/known_hosts{,2} ^/dev/null|cut -d ' ' -f 1| cut -d , -f 1
|
||||
end
|
||||
|
9
init/functions/dirs.fish
Normal file
9
init/functions/dirs.fish
Normal file
|
@ -0,0 +1,9 @@
|
|||
function dirs -d "Print directory stack"
|
||||
echo -n (command pwd)" "
|
||||
for i in $dirstack
|
||||
echo -n $i" "
|
||||
end
|
||||
echo
|
||||
end
|
||||
|
||||
|
20
init/functions/fish_prompt.fish
Normal file
20
init/functions/fish_prompt.fish
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Set the default prompt command. Make sure that every terminal escape
|
||||
# string has a newline before and after, so that fish will know how
|
||||
# long it is.
|
||||
|
||||
function fish_prompt -d (_ "Write out the prompt")
|
||||
|
||||
# Just calculate these once, to save a few cycles when displaying the prompt
|
||||
if not set -q __fish_prompt_hostname
|
||||
set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
|
||||
end
|
||||
|
||||
if not set -q __fish_prompt_normal
|
||||
set -g __fish_prompt_normal (set_color normal)
|
||||
end
|
||||
|
||||
set -l prompt_color (set_color $fish_color_cwd)
|
||||
|
||||
printf '%s@%s %s%s%s> \n' $USER $__fish_prompt_hostname "$prompt_color" (prompt_pwd) "$__fish_prompt_normal"
|
||||
end
|
||||
|
13
init/functions/popd.fish
Normal file
13
init/functions/popd.fish
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
function popd -d "Pop dir from stack"
|
||||
if test $dirstack[1]
|
||||
cd $dirstack[1]
|
||||
else
|
||||
printf (_ "%s: Directory stack is empty...") popd
|
||||
return 1
|
||||
end
|
||||
|
||||
set -e dirstack[1]
|
||||
|
||||
end
|
||||
|
21
init/functions/prompt_pwd.fish
Normal file
21
init/functions/prompt_pwd.fish
Normal file
|
@ -0,0 +1,21 @@
|
|||
|
||||
if test (uname) = Darwin
|
||||
function prompt_pwd -d (_ "Print the current working directory, shortend to fit the prompt")
|
||||
if test "$PWD" != "$HOME"
|
||||
printf "%s" (echo $PWD|sed -e 's|/private||' -e "s|^$HOME|~|" -e 's-/\([^/]\)\([^/]*\)-/\1-g')
|
||||
echo $PWD|sed -e 's-.*/[^/]\([^/]*$\)-\1-'
|
||||
else
|
||||
echo '~'
|
||||
end
|
||||
end
|
||||
else
|
||||
function prompt_pwd -d (_ "Print the current working directory, shortend to fit the prompt")
|
||||
if test "$PWD" != "$HOME"
|
||||
printf "%s" (echo $PWD|sed -e "s|^$HOME|~|" -e 's-/\([^/]\)\([^/]*\)-/\1-g')
|
||||
echo $PWD|sed -e 's-.*/[^/]\([^/]*$\)-\1-'
|
||||
else
|
||||
echo '~'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
8
init/functions/pushd.fish
Normal file
8
init/functions/pushd.fish
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
|
||||
function pushd -d "Push directory to stack"
|
||||
# Comment to avoid set completions
|
||||
set -g dirstack (command pwd) $dirstack
|
||||
cd $argv[1]
|
||||
end
|
||||
|
Loading…
Reference in a new issue