From bcd732aacc6a1bad700c8ceca5974656cbfc3cf2 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Thu, 11 Nov 2021 18:36:14 +0300 Subject: fish: welcome! --- .config/fish/completions/nnn.fish | 45 +++++++++++++ .config/fish/config.fish | 56 ++++++++++++++++ .config/fish/fish_variables | 32 +++++++++ .config/fish/functions/fish_greeting.fish | 3 + .config/fish/functions/fish_prompt.fish | 22 +++++++ .config/fish/functions/fish_right_prompt.fish | 75 ++++++++++++++++++++++ .config/fish/functions/fish_user_key_bindings.fish | 3 + .config/fish/functions/n.fish | 33 ++++++++++ .config/fish/functions/sh.fish | 3 + .config/fish/functions/take.fish | 12 ++++ .config/fish/functions/te.fish | 7 ++ 11 files changed, 291 insertions(+) create mode 100644 .config/fish/completions/nnn.fish create mode 100644 .config/fish/config.fish create mode 100644 .config/fish/fish_variables create mode 100644 .config/fish/functions/fish_greeting.fish create mode 100644 .config/fish/functions/fish_prompt.fish create mode 100644 .config/fish/functions/fish_right_prompt.fish create mode 100644 .config/fish/functions/fish_user_key_bindings.fish create mode 100644 .config/fish/functions/n.fish create mode 100644 .config/fish/functions/sh.fish create mode 100644 .config/fish/functions/take.fish create mode 100644 .config/fish/functions/te.fish diff --git a/.config/fish/completions/nnn.fish b/.config/fish/completions/nnn.fish new file mode 100644 index 0000000..213c5e4 --- /dev/null +++ b/.config/fish/completions/nnn.fish @@ -0,0 +1,45 @@ +# +# Fish completion definition for nnn. +# +# Author: +# Arun Prakash Jana +# + +if test -n "$XDG_CONFIG_HOME" + set sessions_dir $XDG_CONFIG_HOME/.config/nnn/sessions +else + set sessions_dir $HOME/.config/nnn/sessions +end + +complete -c nnn -s a -d 'auto-create NNN_FIFO' +complete -c nnn -s A -d 'disable dir auto-select' +complete -c nnn -s b -r -d 'bookmark key to open' -x -a '(echo $NNN_BMS | awk -F: -v RS=\; \'{print $1"\t"$2}\')' +complete -c nnn -s c -d 'cli-only opener' +complete -c nnn -s C -d 'color by context' +complete -c nnn -s d -d 'start in detail mode' +complete -c nnn -s D -d 'dirs in context color' +complete -c nnn -s e -d 'open text files in $VISUAL/$EDITOR/vi' +complete -c nnn -s E -d 'use EDITOR for undetached edits' +complete -c nnn -s f -d 'use readline history file' +complete -c nnn -s g -d 'regex filters' +complete -c nnn -s H -d 'show hidden files' +complete -c nnn -s i -d 'show current file info' +complete -c nnn -s J -d 'no auto-proceed on select' +complete -c nnn -s K -d 'detect key collision' +complete -c nnn -s l -r -d 'lines to move per scroll' +complete -c nnn -s n -d 'start in type-to-nav mode' +complete -c nnn -s o -d 'open files only on Enter' +complete -c nnn -s p -r -d 'copy selection to file' -a '-\tstdout' +complete -c nnn -s P -r -d 'plugin key to run' -x -a '(echo $NNN_PLUG | awk -F: -v RS=\; \'{print $1"\t"$2}\')' +complete -c nnn -s Q -d 'disable quit confirmation' +complete -c nnn -s r -d 'show cp, mv progress (Linux-only)' +complete -c nnn -s R -d 'disable rollover at edges' +complete -c nnn -s s -r -d 'load session by name' -x -a '@\t"last session" (ls $sessions_dir)' +complete -c nnn -s S -d 'persistent session' +complete -c nnn -s t -r -d 'timeout in seconds to lock' +complete -c nnn -s T -r -d 'a d e r s t v' +complete -c nnn -s u -d 'use selection (no prompt)' +complete -c nnn -s U -d 'show user and group' +complete -c nnn -s V -d 'show program version and exit' +complete -c nnn -s x -d 'notis, sel to system clipboard, xterm title' +complete -c nnn -s h -d 'show program help' diff --git a/.config/fish/config.fish b/.config/fish/config.fish new file mode 100644 index 0000000..84e2340 --- /dev/null +++ b/.config/fish/config.fish @@ -0,0 +1,56 @@ +fish_add_path $HOME/.local/bin + +set --global --export EDITOR nvim +set --global --export PAGER "less -R" +set --global --export MANPAGER nvim +Man! +set --global --export GOPATH $HOME/.local/share/go +set --global --export GPG_TTY (tty) +set --global fish_prompt_pwd_dir_length 0 + +# nnn +set --global --export NNN_OPENER $HOME/.local/bin/nuke +set --global --export NNN_BMS "w:~/nextcloud/personal_wiki;r:~/nextcloud/research;n:~/nextcloud;d:~/down" +set --global --export NNN_COLORS 2136 +set --global --export NNN_FCOLORS c1e2272e006033f7c6d6abc4 +set --global --export NNN_PLUG "d:dragdrop;f:fzcd;h:fzhist;o:fzopen;l:launch;y:x2sel" +set --global --export NNN_TRASH 1 + +set --global --export FZF_DEFAULT_OPTS "--height=40% --layout=reverse --info=inline --border" +set --global --export WECHALLUSER "drocan" +set --global --export WECHALLTOKEN "35624-0D38B-A2F16-A98B0-5963D-6DF19" +set --global --export RUST_SRC_PATH (rustc --print sysroot)/lib/rustlib/src/rust/library/ +set --global --export NLTK_DATA "$HOME/.local/share/nltk_data" + +if status is-interactive + abbr --add --global v 'nvim' + abbr --add --global nt 'neomutt' + abbr --add --global rm 'rm -i' + abbr --add --global cp 'cp -i' + abbr --add --global mv 'mv -i' + abbr --add --global free 'free -m' + abbr --add --global df 'df -h' + abbr --add --global C 'xsel -b' # Copy to clipboard + abbr --add --global bc 'bc -l' + abbr --add --global ledger "ledger -f ~/nextcloud/virtuals/ledger.ledger" + abbr --add --global report "report -f ~/nextcloud/virtuals/ledger.ledger" + abbr --add --global think 'tickle +1d' #think it over + abbr --add --global lim 'nvim /home/yigit/nextcloud/virtuals/ledger.ledger' + abbr --add --global maybe 'task due:someday list' + abbr --add --global music 'mpv --no-vid' + abbr --add --global s "du -hs * | sort -rh | head -5" + abbr --add --global b "buku --suggest --colors 'onlxm'" + abbr --add --global tp 'trash-put' + abbr --add --global ls 'exa' + abbr --add --global wim 'nvim /home/yigit/nextcloud/personal_wiki/text/index.wiki' + abbr --add --global torem 'cd /home/yigit/nextcloud/virtuals/remind/' + abbr --add --global taw 'task add +next +@work' + abbr --add --global tat 'task add +next +@tablet pro:res.toread' + abbr --add --global tre 'exa -l -T -L 2 --header --git-ignore -F -d -I node_modules' + abbr --add --global guno 'git status -uno' + abbr --add --global bo 'bukuopener' + abbr --add --global re 'rem -gaad -@2' + abbr --add --global in 'task add +in' + abbr --add --global inc 'task +in +PENDING count' + + zoxide init fish | source +end diff --git a/.config/fish/fish_variables b/.config/fish/fish_variables new file mode 100644 index 0000000..588049d --- /dev/null +++ b/.config/fish/fish_variables @@ -0,0 +1,32 @@ +# This file contains fish universal variable definitions. +# VERSION: 3.0 +SETUVAR __fish_initialized:3100 +SETUVAR fish_color_autosuggestion:969896 +SETUVAR fish_color_cancel:\x2dr +SETUVAR fish_color_command:c397d8 +SETUVAR fish_color_comment:e7c547 +SETUVAR fish_color_cwd:green +SETUVAR fish_color_cwd_root:red +SETUVAR fish_color_end:c397d8 +SETUVAR fish_color_error:d54e53 +SETUVAR fish_color_escape:00a6b2 +SETUVAR fish_color_history_current:\x2d\x2dbold +SETUVAR fish_color_host:normal +SETUVAR fish_color_host_remote:yellow +SETUVAR fish_color_match:\x2d\x2dbackground\x3dbrblue +SETUVAR fish_color_normal:normal +SETUVAR fish_color_operator:00a6b2 +SETUVAR fish_color_param:7aa6da +SETUVAR fish_color_quote:b9ca4a +SETUVAR fish_color_redirection:70c0b1 +SETUVAR fish_color_search_match:bryellow\x1e\x2d\x2dbackground\x3dbrblack +SETUVAR fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrblack +SETUVAR fish_color_status:red +SETUVAR fish_color_user:brgreen +SETUVAR fish_color_valid_path:\x2d\x2dunderline +SETUVAR fish_key_bindings:fish_default_key_bindings +SETUVAR fish_pager_color_completion:normal +SETUVAR fish_pager_color_description:B3A06D\x1eyellow +SETUVAR fish_pager_color_prefix:normal\x1e\x2d\x2dbold\x1e\x2d\x2dunderline +SETUVAR fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan +SETUVAR fish_user_paths:/home/yigit/\x2elocal/bin diff --git a/.config/fish/functions/fish_greeting.fish b/.config/fish/functions/fish_greeting.fish new file mode 100644 index 0000000..ee7303d --- /dev/null +++ b/.config/fish/functions/fish_greeting.fish @@ -0,0 +1,3 @@ +function fish_greeting + fortune -a | cowsay -f small | lolcat +end diff --git a/.config/fish/functions/fish_prompt.fish b/.config/fish/functions/fish_prompt.fish new file mode 100644 index 0000000..24e6e71 --- /dev/null +++ b/.config/fish/functions/fish_prompt.fish @@ -0,0 +1,22 @@ +function fish_prompt + set -l __last_command_exit_status $status + + set -l cyan (set_color -o cyan) + set -l red (set_color -o red) + set -l green (set_color -o green) + set -l normal (set_color normal) + + set -l marker_color "$green" + if test $__last_command_exit_status != 0 + set marker_color "$red" + end + + set -l marker "$marker_color" "δ" + if fish_is_root_user + set marker "$marker_color# " + end + + set -l cwd $cyan (string join / (string split -rn -m3 / (prompt_pwd) | tail -n3)) + + echo -n -s $marker ' '$cwd $normal ' ' +end diff --git a/.config/fish/functions/fish_right_prompt.fish b/.config/fish/functions/fish_right_prompt.fish new file mode 100644 index 0000000..0dbcc37 --- /dev/null +++ b/.config/fish/functions/fish_right_prompt.fish @@ -0,0 +1,75 @@ +function fish_right_prompt -d "Write out the right prompt" + + if not set -q -g __fish_right_prompt_functions_defined + set -g __fish_right_prompt_functions_defined + function _git_branch_name + set -l branch (git symbolic-ref --quiet HEAD 2>/dev/null) + if set -q branch[1] + echo (string replace -r '^refs/heads/' '' $branch) + else + echo (git rev-parse --short HEAD 2>/dev/null) + end + end + + function _is_git_dirty + not command git diff-index --cached --quiet HEAD -- &>/dev/null + or not command git diff --no-ext-diff --quiet --exit-code &>/dev/null + end + + function _is_git_repo + type -q git + or return 1 + git rev-parse --git-dir >/dev/null 2>&1 + end + + function _hg_branch_name + echo (hg branch 2>/dev/null) + end + + function _is_hg_dirty + set -l stat (hg status -mard 2>/dev/null) + test -n "$stat" + end + + function _is_hg_repo + fish_print_hg_root >/dev/null + end + + function _repo_branch_name + _$argv[1]_branch_name + end + + function _is_repo_dirty + _is_$argv[1]_dirty + end + + function _repo_type + if _is_hg_repo + echo hg + return 0 + else if _is_git_repo + echo git + return 0 + end + return 1 + end + end + + set -l yellow (set_color -o yellow) + set -l red (set_color -o red) + set -l blue (set_color -o blue) + + set -l repo_info + if set -l repo_type (_repo_type) + set -l repo_branch $red(_repo_branch_name $repo_type) + set repo_info "$blue $repo_type:($repo_branch$blue)" + + if _is_repo_dirty $repo_type + set -l dirty "$yellow ✗" + set repo_info "$repo_info$dirty" + end + end + + set hour $blue(date '+%R') + echo -n -s $repo_info ' ' $hour +end diff --git a/.config/fish/functions/fish_user_key_bindings.fish b/.config/fish/functions/fish_user_key_bindings.fish new file mode 100644 index 0000000..ff0d9f3 --- /dev/null +++ b/.config/fish/functions/fish_user_key_bindings.fish @@ -0,0 +1,3 @@ +function fish_user_key_bindings + fzf_key_bindings +end diff --git a/.config/fish/functions/n.fish b/.config/fish/functions/n.fish new file mode 100644 index 0000000..042011c --- /dev/null +++ b/.config/fish/functions/n.fish @@ -0,0 +1,33 @@ +function n --wraps=nnn --description 'support nnn quit and change directory' + # Block nesting of nnn in subshells + if test -n "$NNNLVL" + if [ (expr $NNNLVL + 0) -ge 1 ] + echo "nnn is already running" + return + end + end + + # The behaviour is set to cd on quit (nnn checks if NNN_TMPFILE is set) + # To cd on quit only on ^G, remove the "-x" as in: + # set NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd" + # (or, to a custom path: set NNN_TMPFILE "/tmp/.lastd") + # or, export NNN_TMPFILE after nnn invocation + if test -n "$XDG_CONFIG_HOME" + set NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd" + else + set NNN_TMPFILE "$HOME/.config/nnn/.lastd" + end + + # Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn + # stty start undef + # stty stop undef + # stty lwrap undef + # stty lnext undef + + nnn -c $argv + + if test -e $NNN_TMPFILE + source $NNN_TMPFILE + rm $NNN_TMPFILE + end +end diff --git a/.config/fish/functions/sh.fish b/.config/fish/functions/sh.fish new file mode 100644 index 0000000..3b7ae9a --- /dev/null +++ b/.config/fish/functions/sh.fish @@ -0,0 +1,3 @@ +function sh --wraps=ssh --description 'ssh with correct TERM' + TERM=xterm-256color ssh $argv +end diff --git a/.config/fish/functions/take.fish b/.config/fish/functions/take.fish new file mode 100644 index 0000000..407cf36 --- /dev/null +++ b/.config/fish/functions/take.fish @@ -0,0 +1,12 @@ +function take --description 'Create a directory and cd to it' + command mkdir $argv + if test $status = 0 + switch $argv[(count $argv)] + case '-*' + + case '*' + cd $argv[(count $argv)] + return + end + end +end diff --git a/.config/fish/functions/te.fish b/.config/fish/functions/te.fish new file mode 100644 index 0000000..b0adca6 --- /dev/null +++ b/.config/fish/functions/te.fish @@ -0,0 +1,7 @@ +function te --description "take a temporary directory" + if set -q argv[1] + cd (command mktemp -d /tmp/$argv[1].XXXX) + else + cd (command mktemp -d /tmp/.XXXX) + end +end -- cgit v1.2.3-70-g09d2