210 lines
5.4 KiB
Nix
210 lines
5.4 KiB
Nix
{ ... }:
|
|
|
|
{
|
|
programs.fish.shellAbbrs =
|
|
{ e = "nvim";
|
|
l = "ls -lh";
|
|
ip = "ip -c";
|
|
iftop = "iftop -m 70M";
|
|
};
|
|
|
|
programs.fish.shellAliases =
|
|
{ namecoin-cli = "namecoin-cli -conf=$XDG_CONFIG_HOME/namecoin"; };
|
|
|
|
programs.fish.loginShellInit =
|
|
''
|
|
# Start abduco in ssh
|
|
if set -q SSH_CLIENT
|
|
# start abduco on ssh
|
|
if not set -q ABDUCO_SESSION
|
|
exec abduco -A ssh fish
|
|
else if test $SHLVL -eq 1
|
|
tput rmcup
|
|
end
|
|
end
|
|
'';
|
|
|
|
programs.fish.interactiveShellInit =
|
|
''
|
|
## Fish settings
|
|
|
|
# mixed emacs/vi
|
|
fish_hybrid_key_bindings
|
|
|
|
# kj to normal mode
|
|
bind -M insert kj "
|
|
if commandline -P;
|
|
commandline -f cancel;
|
|
else;
|
|
set fish_bind_mode default;
|
|
commandline -f backward-char repaint-mode;
|
|
end"
|
|
|
|
# fix unquoted URLs
|
|
set -U fish_features ampersand-nobg-in-token qmark-noglob
|
|
# change default cursor
|
|
set fish_cursor_insert underscore
|
|
|
|
|
|
## Color scheme
|
|
|
|
# syntax highlighting
|
|
set fish_color_command green
|
|
set fish_color_param normal
|
|
set fish_color_comment brcyan
|
|
set fish_color_operator purple
|
|
set fish_color_escape bryellow
|
|
set fish_color_redirection blue
|
|
set fish_color_selection --background=black
|
|
|
|
# completion/history
|
|
set fish_pager_color_prefix yellow
|
|
set fish_pager_color_description brblue
|
|
set fish_pager_color_progress brblack --background=black
|
|
set fish_color_search_match --background=black
|
|
|
|
# man pages colors
|
|
# bold, blink stop
|
|
set -x LESS_TERMCAP_md (set_color -o bryellow)
|
|
set -x LESS_TERMCAP_mb (set_color -u magenta)
|
|
set -x LESS_TERMCAP_me (set_color normal)
|
|
# standout start/stop
|
|
set -x LESS_TERMCAP_so (set_color brblue -b black)
|
|
set -x LESS_TERMCAP_se (set_color normal -b normal)
|
|
# underline start/stop
|
|
set -x LESS_TERMCAP_us (set_color -u brmagenta)
|
|
set -x LESS_TERMCAP_ue (set_color normal)
|
|
|
|
# used default LS_COLORS
|
|
eval (dircolors | sed 's/\(\w\+\)=/set \1 /')
|
|
|
|
|
|
## Aliases
|
|
|
|
# start process and detach
|
|
function start
|
|
nohup $argv > /dev/null 2>&1 &; disown
|
|
end
|
|
|
|
# start process without network access
|
|
function nnet
|
|
unshare -nc fish -ic "$argv"
|
|
end
|
|
|
|
# interactively rename files
|
|
function vimv
|
|
set tmp (mktemp --tmpdir -d vimv.XXX)
|
|
if set -q argv[1]
|
|
# directory listing
|
|
find $argv[1] -maxdepth 1 | sort | cat -n | tee $tmp/before > $tmp/after
|
|
else
|
|
# read from stdin
|
|
cat -n - | tee $tmp/before > $tmp/after
|
|
end
|
|
$EDITOR $tmp/after
|
|
# only print differing lines
|
|
awk '
|
|
NR==FNR { line=$0; sub($1, "", line); sub(/\s+/, "", line); lines[$1]=line; next }
|
|
NR!=FNR { line=$0; sub($1, "", line); sub(/\s+/, "", line);
|
|
if (!($1 in lines)) { printf("rm -vr \"%s\"\n", line); next }
|
|
if (lines[$1] != line) printf("mv -vin \"%s\" \"%s\"\n", line, lines[$1])
|
|
}
|
|
' $tmp/after $tmp/before | sh
|
|
rm -r $tmp
|
|
end
|
|
'';
|
|
|
|
programs.fish.promptInit =
|
|
''
|
|
# Outputs colored text
|
|
function color
|
|
set_color $argv[1]
|
|
for i in $argv[2..-1]
|
|
echo -n $i
|
|
end
|
|
set_color normal
|
|
end
|
|
|
|
# Git branch info
|
|
function git_branch
|
|
if not test -f .git/HEAD
|
|
return
|
|
end
|
|
|
|
set branch (git rev-parse --abbrev-ref HEAD 2> /dev/null)
|
|
if test $status -ne 0
|
|
set branch (cut -f 3 -d '/' .git/HEAD)
|
|
else if test $branch = HEAD
|
|
set branch (head -c 10 .git/HEAD)
|
|
end
|
|
|
|
timeout 0.1 git diff-files --quiet 2>/dev/null
|
|
if test $status -eq 1
|
|
set branch (color yellow $branch'*')
|
|
else
|
|
set branch (color green $branch)
|
|
end
|
|
|
|
timeout 0.1 git status --porcelain 2>/dev/null 1>| read untracked
|
|
if test -n "$untracked"
|
|
set dirty (color red '*')
|
|
end
|
|
|
|
echo " <$branch$dirty>"
|
|
end
|
|
|
|
# Left prompt
|
|
function fish_prompt
|
|
if fish_is_root_user
|
|
set prompt (color blue Λ)
|
|
set user (color red (whoami))
|
|
else
|
|
set prompt (color blue λ)
|
|
set user (color green (whoami))
|
|
end
|
|
|
|
if test \( "$LINES" -lt 10 \) -o \( "$COLUMNS" -lt 30 \)
|
|
echo "$prompt "
|
|
return
|
|
end
|
|
|
|
if set -q SSH_CLIENT
|
|
set host (color yellow (hostname))
|
|
else
|
|
set host (color green (hostname))
|
|
end
|
|
|
|
set git (git_branch)
|
|
set path (color cyan (prompt_pwd))
|
|
|
|
switch $fish_bind_mode
|
|
case default
|
|
set mode (color blue n)
|
|
case insert
|
|
set mode (color red i)
|
|
case visual
|
|
set mode (color yellow v)
|
|
end
|
|
|
|
echo "$user@$host $mode$path$git"
|
|
echo "$prompt "
|
|
end
|
|
|
|
# Right prompt
|
|
function fish_right_prompt
|
|
set code $status
|
|
if test $code -ne 0
|
|
set exitcode (color red $code" ⏎")
|
|
end
|
|
if string match -q '/nix*' $PATH[1]
|
|
set nix " <"(color blue nix)">"
|
|
end
|
|
echo "$exitcode$nix"
|
|
end
|
|
|
|
function fish_mode_prompt; end
|
|
function fish_greeting; end
|
|
'';
|
|
|
|
}
|