fish: Init

master
Pierre Neidhardt 2016-10-13 14:39:04 +05:30
parent 40aba20b8c
commit 976538a385
10 changed files with 333 additions and 0 deletions

View File

@ -0,0 +1,8 @@
## TODO: This fixes upstream bug, report!
complete -c fusermount --description "Mount point" -x -a '(__fish_print_mounted)'
complete -c fusermount -s h --description "Display help and exit"
complete -c fusermount -s v --description "Display version and exit"
complete -c fusermount -s o -x --description "Mount options"
complete -c fusermount -s u --description "Unmount"
complete -c fusermount -s q --description "Quiet"
complete -c fusermount -s z --description "Lazy unmount"

57
.config/fish/config.fish Normal file
View File

@ -0,0 +1,57 @@
## fish working paths
set -q XDG_DATA_HOME; or set -l XDG_DATA_HOME $HOME/.local/share
set -q XDG_CONFIG_HOME; or set -l XDG_CONFIG_HOME $HOME/.config
set -q fish_data_path; or set -g fish_data_path $XDG_DATA_HOME/fish
set -q fish_config_path; or set -g fish_config_path $XDG_CONFIG_HOME/fish
## cdhist options
set -g fish_cdhist_path $fish_data_path/fish_cdhist
set -g fish_cdhist_max 100
## Go back to last cdhist folder. Run this before the SHELL_FILEBROWSER hook.
if grep -q . $fish_cdhist_path ^ /dev/null
set dirprev (cat $fish_cdhist_path)
set -q dirprev[$fish_cdhist_max]; and set dirprev $dirprev[-$fish_cdhist_max..-1]
cd $dirprev[(count $dirprev)]
end
## Run the following
## sh -c 'export SHELL_FILEBROWSER=true; exec $TERMCMD'
## and this will autostart the file browser.
[ -n "$SHELL_FILEBROWSER" ]; and set -u SHELL_FILEBROWSER; and ranger
## Start at a specific location. Useful when switching to a shell from a browser
## for instance.
[ -n "$SHELL_CD" ]; and cd $SHELL_CD; and set -u SHELL_CD
## Misc
set fish_greeting
## Colors
## For custom prompt.
set fish_color_user brcyan
set fish_color_hostname brcyan
## Aliases
function ls --description 'List contents of directory'
set -l param --color=auto
if isatty 1
set param $param --indicator-style=classify
end
if [ (uname -o) = "GNU/Linux" ]
set param $param --group-directories-first
end
command ls $param $argv
end
alias l 'ls -1'
alias la 'll -lAh'
alias mkdir 'mkdir -p'
function mkcd -a folder -d 'Make directory and change into it.'
mkdir -p $folder
cd $folder
end
if type -pq pacman
source $fish_config_path/pacman.fish
end

View File

@ -0,0 +1,36 @@
# Wrap the builtin cd command to maintain a permanent directory history.
function cd --description "Change directory"
if test (count $argv) -gt 1
printf "%s\n" (_ "Too many args for cd command")
return 1
end
# Skip history in subshells.
if status --is-command-substitution
builtin cd $argv
return $status
end
if test "$argv" = "-"
set argv $dirprev[(math (count $dirprev) - 1)]
end
builtin cd $argv
set -l cd_status $status
if test $cd_status -eq 0
if set -q dirprev
## Remove duplicates.
set -g dirprev (string match -v $PWD $dirprev) $PWD
set -q dirprev[$fish_cdhist_max]; and set dirprev $dirprev[-$fish_cdhist_max..-1]
## Save history.
string join \n $dirprev > $fish_cdhist_path
else
set -g dirprev $PWD
end
set -e dirnext
set -g __fish_cd_direction prev
end
return $cd_status
end

View File

@ -0,0 +1,12 @@
function describe -d 'Extend on "type" for executables'
for i in $argv
switch (type -t $i)
case file
set -l path (type -p $i)
ls -l $path
file $path | cut -d':' -f2 | cut -b 2-
case '*'
type $i
end
end
end

View File

@ -0,0 +1,27 @@
function fish_prompt
set HOST (hostname)
printf "%s%s%s%s%s" (set_color -o)'(' \
(set_color normal) \
(set_color $fish_color_user)$USER \
(set_color normal) \
(set_color -o)@ \
(set_color normal) \
(set_color $fish_color_hostname)$HOST \
(set_color normal) \
(set_color -o)'}'
## Path
set -l cwd_color $fish_color_cwd
if test (id -u) -eq 0
set -l cwd_color $fish_color_cwd_root
end
set PROMPT_PWD (prompt_pwd)
printf "%s%s%s%s" \
(set_color -o)'[' \
(set_color -o $cwd_color)$PROMPT_PWD \
(set_color normal) \
(set_color -o)']'
echo
echo '> '
end

View File

@ -0,0 +1,10 @@
function fish_user_key_bindings
## fzf
if type -pq fzf
source $fish_config_path/fzf.fish
end
## Ranger
type -q ranger; and bind \e\cb ranger
end

View File

@ -0,0 +1,35 @@
function man --description 'Color and justify the on-line manual pages'
## Work around the "builtin" manpage that everything symlinks to,
## by prepending our fish datadir to man. This also ensures that man gives fish's
## man pages priority, without having to put fish's bin directories first in $PATH
# Justify man pager to current window size.
set -q MANWIDTH; and [ $COLUMNS -lt $MANWIDTH ]; and set -lx MANWIDTH $COLUMNS
## Color when using LESS.
## mb = ?
## md = bold (titles, commands)
## so = status bar
## us = italic (arguments, files)
set -lx LESS_TERMCAP_mb (printf "\e[1;31m")
set -lx LESS_TERMCAP_md (printf "\e[0;36m")
set -lx LESS_TERMCAP_me (printf "\e[0m")
set -lx LESS_TERMCAP_se (printf "\e[0m")
set -lx LESS_TERMCAP_so (printf "\e[1;4;37m")
set -lx LESS_TERMCAP_ue (printf "\e[0m")
set -lx LESS_TERMCAP_us (printf "\e[0;33m")
# Notice local but exported variable
set -lx MANPATH (string join : $MANPATH)
if test -z "$MANPATH"
type -q manpath
and set MANPATH (command manpath)
end
set -l fish_manpath (dirname $__fish_datadir)/fish/man
if test -d "$fish_manpath" -a -n "$MANPATH"
set MANPATH "$fish_manpath":$MANPATH
end
# If fish's man pages could not be found, just invoke man normally
command man $argv
end

View File

@ -0,0 +1,17 @@
# Compatible with ranger >= 1.4.2.
#
# To undo the effect of this function, you can type "cd -" to return to the
# original directory.
function ranger -d 'Run ranger and sync folders with shell'
[ (count $argv) -eq 0 ]; and set argv .
set -l tempfile (mktemp)
command ranger --choosedir="$tempfile" $argv
if grep -q . "$tempfile" ^ /dev/null
set -l dest (cat -- "$tempfile")
## TODO: Clear prompt so that shorter path does not print on top of longer
## path. Could be a multi-line issue. Happens on every repaint, e.g. with
## fzf widgets as well.
[ "$dest" != "$PWD" ]; and cd $dest; and commandline -f repaint
end
rm -f -- "$tempfile"
end

68
.config/fish/fzf.fish Normal file
View File

@ -0,0 +1,68 @@
fzf_key_bindings
bind \cT transpose-chars
bind \e\ct fzf-file-widget
bind \ec capitalize-word
bind \eC fzf-cd-widget
function __fzf-selector -d 'fzf commandline and print selection back to commandline. Awesome!'
set -l cmd (commandline)
[ $cmd ]; or return
eval $cmd | eval (__fzfcmd) -m --tiebreak=index --toggle-sort=ctrl-r | string join ' ' | read -l result
[ "$result" ]; and commandline -- $result
commandline -f repaint
end
bind \e\cm __fzf-selector
## DONE: Report missing (commandline) upstream.
## TODO: Report use of 'read'.
function fzf-history-widget
history | eval (__fzfcmd) +m --tiebreak=index --toggle-sort=ctrl-r $FZF_CTRL_R_OPTS -q '(commandline)' | read -l result
and commandline -- $result
commandline -f repaint
end
## Like original but uses last token as root for 'find'.
## If last token is a path, you can use it as $cwd in FZF_CTRL_T_COMMAND to
## restrict search to this path. $cwd will be suppressed from commandline to
## ensure clean output from the search results.
## TODO: Report upstream. Makes '**' obsolete for bash and zsh.
function fzf-file-widget
set -l cwd_esc (commandline -t)
## The commandline token might be escaped, we need to unescape it.
set -l cwd (eval "echo $cwd_esc")
if [ ! -d $cwd ]
set cwd .
end
set -q FZF_CTRL_T_COMMAND; or set -l FZF_CTRL_T_COMMAND "
command find -L \$cwd \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
-o -type f -print \
-o -type d -print \
-o -type l -print 2> /dev/null | sed 1d"
if eval $FZF_CTRL_T_COMMAND | eval (__fzfcmd) -m $FZF_CTRL_T_OPTS > $TMPDIR/fzf.result
if [ $cwd != . ]
## Remove path from commandline: it will be
set -l cmd (commandline)
set -l len (math (string length $cmd) - (string length $cwd_esc))
commandline -- (string sub -l $len (commandline))
end
for i in (seq 20); commandline -i (cat $TMPDIR/fzf.result | __fzf_escape) 2> /dev/null; and break; sleep 0.1; end
end
commandline -f repaint
rm -f $TMPDIR/fzf.result
end
function fzf-bcd-widget -d 'cd backwards'
pwd | nawk -v RS=/ '/\n/ {exit} {p=p $0 "/"; print p}' | eval (__fzfcmd) +m --tac | read -l result
[ $result ]; and cd $result
commandline -f repaint
end
bind \e\cL fzf-bcd-widget
function fzf-cdhist-widget -d 'cd to one of the previously visited location'
string join \n $dirprev | eval (__fzfcmd) +m | read -l result
[ $result ]; and cd $result
commandline -f repaint
end
bind \er fzf-cdhist-widget

63
.config/fish/pacman.fish Normal file
View File

@ -0,0 +1,63 @@
## TODO: Remove unnecessary aliases.
set -l listinstalled "(pacman -Q | string replace ' ' \t)"
set -l listall "(__fish_print_packages)"
function pacfiles -d 'List of files in pacman package packages sorted by size'
pacman -Qlq $argv | grep -v '/$' | xargs du -cbh | sort -h
end
complete -c pacfiles -a "$listinstalled"
function pel
set -l result
pacman -Qlq $argv | grep -v '/$' | eval (__fzfcmd) -m --tiebreak=index --toggle-sort=ctrl-r | while read -l r; set result $result $r; end
[ "$result" ]; and eval $EDITOR $result
end
complete -c pel -a "$listinstalled"
function pi
sudo pacman -S --needed $argv
end
complete -c pi -a "$listall"
function pli -a size -d 'Pacman last installed packages'
[ $size ]; or set size 30
expac -t '%F %T' '%-8l %n' | sort -rn | head -$size
end
function pqi
pacman -Qi $argv
end
complete -c pqi -a "$listinstalled"
function pql -d 'Get detailed file list (no folders) for the specified packages'
pacman -Ql $argv | grep -v '/$'
end
complete -c pql -a "$listinstalled"
function pqo
pacman -Qo $argv
end
complete -c pqo -a '(__fish_complete_command)'
function pqs
pacman -Qs $argv
end
function pr
sudo pacman -Rs $argv
end
complete -c pr -a "$listinstalled"
function psi
pacman -Si $argv
end
complete -c psi -a "$listall"
function pss
pacman -Ss $argv
end
function pu -d 'Run pacman system update'
yes | sudo pacman -Sc; and sudo pacman -Syu
end