1
1
Fork 0

Add fish config

This commit is contained in:
Jonathan Schleifer 2020-01-21 00:11:28 +00:00
parent c4af1c28aa
commit f1d4f3fd36
16 changed files with 215 additions and 0 deletions

View file

@ -0,0 +1,7 @@
# pkgsrc does not like MAKEFLAGS being set
function bmake
if string match -q -r '/pkgsrc$|/pkgsrc/' $PWD
set -lx MAKEFLAGS
end
command bmake $argv
end

View file

@ -0,0 +1,51 @@
function cd --description 'Change directory'
set -l MAX_DIR_HIST 25
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
# Avoid set completions.
set -l previous $PWD
if test "$argv" = "-"
if test "$__fish_cd_direction" = "next"
nextd
else
prevd
end
return $status
end
# allow explicit "cd ." if the mount-point became stale in the meantime
if test "$argv" = "."
cd "$PWD"
return $status
end
builtin cd $argv
set -l cd_status $status
if test $cd_status -eq 0 -a "$PWD" != "$previous"
set -q dirprev
or set -l dirprev
set -q dirprev[$MAX_DIR_HIST]
and set -e dirprev[1]
set -g -a dirprev $previous
set -e dirnext
set -g __fish_cd_direction prev
end
if test $cd_status -eq 0
ls
end
return $cd_status
end

View file

@ -0,0 +1,7 @@
function fgrep
if which ggrep >/dev/null
command ggrep -F --color=auto $argv
else
command fgrep --color=auto $argv
end
end

View file

@ -0,0 +1,28 @@
function fish_prompt --description 'Write out the prompt'
set -l color_cwd
set -l suffix
switch "$USER"
case root toor
if set -q fish_color_cwd_root
set color_cwd $fish_color_cwd_root
else
set color_cwd $fish_color_cwd
end
set suffix '#'
case '*'
set color_cwd $fish_color_cwd
set suffix '$'
end
set -l branch (git symbolic-ref HEAD 2>/dev/null)
set branch (string replace -r "^refs/heads/" "" $branch)
set -l vcs
if test -n "$branch" -a "$branch" != "master"
set vcs "($branch)"
end
echo -n -s (set_color $fish_color_host) (prompt_hostname) ':' \
(set_color $color_cwd) (prompt_pwd) \
(set_color $fish_color_vcs) "$vcs" \
(set_color $fish_color_suffix) "$suffix "
end

View file

@ -0,0 +1,14 @@
function fish_right_prompt
set -l code $status
set -l jobs (jobs | wc -l)
if test $jobs -gt 0
set_color $fish_color_jobs
echo "$jobs "
end
if test $code -gt 0
set_color $fish_color_error
echo "$code "
end
end

View file

@ -0,0 +1,4 @@
function gpgssh
set -x SSH_AUTH_SOCK $HOME/.gnupg/S.gpg-agent.ssh
ssh $argv
end

View file

@ -0,0 +1,7 @@
function grep
if which ggrep >/dev/null
command ggrep --color=auto $argv
else
command grep --color=auto $argv
end
end

View file

@ -0,0 +1,7 @@
function hybrid_bindings --description 'Vi bindings with a bit of Emacs bindings'
for mode in default insert visual
fish_default_key_bindings -M $mode
end
fish_vi_key_bindings --no-erase
end

View file

@ -0,0 +1,3 @@
function ixio
curl -F 'f:1=<=' ix.io
end

View file

@ -0,0 +1,7 @@
function ls --description 'List contents of directory'
if which gls >/dev/null
command gls --color=auto $argv
else
command ls --color=auto $argv
end
end

View file

@ -0,0 +1,5 @@
# To work around mpv not liking locales that use , as a decimal separator
function mpv
set -x LC_ALL C
command mpv $argv
end

View file

@ -0,0 +1,16 @@
function prompt_pwd --description 'Print the current working directory'
set -l options 'h/help'
argparse -n prompt_pwd --max-args=0 $options -- $argv
or return
if set -q _flag_help
__fish_print_help prompt_pwd
return 0
end
# Replace $HOME with "~"
set realhome ~
set -l tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $PWD)
basename $tmp
end

View file

@ -0,0 +1,13 @@
function pw
set -l clipboard
if which pbcopy >/dev/null
set clipboard pbcopy
else if which xclip >/dev/null
set clipboard xclip
else
echo "No clipboard handler found!"
return 1
end
cryptopassphrase -k ~/.scrypt-pwgen.key $argv | tr -d '\n' | $clipboard
end

View file

@ -0,0 +1,5 @@
# pkgsrc does not like MAKEFLAGS being set
function url2pkg
set -lx MAKEFLAGS
command url2pkg $argv
end