From e5f5d2c785f384e4e93e28ee19c807336beee9b7 Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Thu, 30 Sep 2021 13:54:42 +0800 Subject: [PATCH] feat: add nnn and vim-floaterm --- bin/ns | 3 +++ cli/fish/config.fish | 6 +++++- cli/fish/functions/n.fish | 37 +++++++++++++++++++++++++++++++++++++ cli/nnn.sh | 22 ++++++++++++++++++++++ cli/nnn/n.fish | 37 +++++++++++++++++++++++++++++++++++++ cli/vim/init.vim | 17 +++++++++++++++-- 6 files changed, 119 insertions(+), 3 deletions(-) create mode 100755 bin/ns create mode 100644 cli/fish/functions/n.fish create mode 100755 cli/nnn.sh create mode 100644 cli/nnn/n.fish diff --git a/bin/ns b/bin/ns new file mode 100755 index 0000000..e35d5b5 --- /dev/null +++ b/bin/ns @@ -0,0 +1,3 @@ +#!/bin/sh + +xargs -0 ls -l < "${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection" diff --git a/cli/fish/config.fish b/cli/fish/config.fish index d12d8e7..6d84f39 100644 --- a/cli/fish/config.fish +++ b/cli/fish/config.fish @@ -13,7 +13,8 @@ if status is-interactive # === less configuration # no line-wrapping, good for `docker ps` - set -gx LESS "-SRXF" + #set -gx LESS "-SRXF" + set -gx LESS "-SRX" # for nnn help to how, remove F # === nvm configuration set -gx nvm_mirror http://npm.taobao.org/mirrors/node @@ -22,6 +23,9 @@ if status is-interactive # change OTHER-WRITABLE color for `ls` command set -gx LS_COLORS 'ow=34;42;40' + # === nnn configuration + set -gx NNN_PLUG 'c:fzcd;m:nmount;x:!chmod +x $nnn;d:dragdrop' + # === bat configuration set -gx BAT_THEME 'OneHalfDark' set -gx MANPAGER "sh -c 'col -bx | bat -l man -p'" diff --git a/cli/fish/functions/n.fish b/cli/fish/functions/n.fish new file mode 100644 index 0000000..2e63395 --- /dev/null +++ b/cli/fish/functions/n.fish @@ -0,0 +1,37 @@ +# Rename this file to match the name of the function +# e.g. ~/.config/fish/functions/n.fish +# or, add the lines to the 'config.fish' file. + +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 -x NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd" + else + set -x 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 $argv + + if test -e $NNN_TMPFILE + source $NNN_TMPFILE + rm $NNN_TMPFILE + end +end diff --git a/cli/nnn.sh b/cli/nnn.sh new file mode 100755 index 0000000..3fc1d92 --- /dev/null +++ b/cli/nnn.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +set -e +DIR=$(dirname "$(readlink -f "$0")") +. "$DIR/../env.sh" + +log 'Setting up nnn' + +# setup package mirror for CHINA +case "$PM" in + apt) + echo TODO + exit -1 + ;; + pacman) + sudo pacman -S --noconfirm --needed nnn + yay -S --noconfirm --needed dragon-drag-and-drop +esac + +# configuration +lnsf "$DIR/nnn/n.fish" "$XDG_CONFIG_HOME/fish/functions/n.fish" +cp -r /usr/share/nnn/plugins/. "$XDG_CONFIG_HOME/nnn/plugins" diff --git a/cli/nnn/n.fish b/cli/nnn/n.fish new file mode 100644 index 0000000..2e63395 --- /dev/null +++ b/cli/nnn/n.fish @@ -0,0 +1,37 @@ +# Rename this file to match the name of the function +# e.g. ~/.config/fish/functions/n.fish +# or, add the lines to the 'config.fish' file. + +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 -x NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd" + else + set -x 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 $argv + + if test -e $NNN_TMPFILE + source $NNN_TMPFILE + rm $NNN_TMPFILE + end +end diff --git a/cli/vim/init.vim b/cli/vim/init.vim index e40ca9c..977dcdd 100644 --- a/cli/vim/init.vim +++ b/cli/vim/init.vim @@ -50,7 +50,7 @@ noremap noremap vnoremap p pgvy -nnoremap q :qall +nnoremap Q :qall nnoremap v nnoremap s :b# @@ -68,6 +68,7 @@ nnoremap k k nnoremap l l nnoremap oo o nnoremap q q +nnoremap x :!chmod +x % function! GetXCopyCmd() @@ -169,6 +170,7 @@ Plug 'alvan/vim-closetag' "Plug 'francoiscabrol/ranger.vim' Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } Plug 'junegunn/fzf.vim' +Plug 'voldikss/vim-floaterm' Plug 'preservim/nerdtree' if $VIM_MODE == 'enhanced' @@ -367,9 +369,20 @@ highlight SpellBad gui=undercurl " commitmsg autocmd BufEnter,BufRead commitmsg.md :set colorcolumn=100 -" nerdtree +" ==== nerdtree ==== nnoremap t :NERDTreeToggle " go organize import on save +" ==== golang ==== command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') autocmd BufWritePre *.go :OR + +" ==== floaterm ==== +nnoremap tt :FloatermNew nnn +let g:floaterm_autohide=1 +let g:floaterm_autoclose=1 +let g:floaterm_opener='edit' +let g:floaterm_keymap_new = '' +let g:floaterm_keymap_prev = '' +let g:floaterm_keymap_next = '' +let g:floaterm_keymap_toggle = ''