From d34d652a2dfb588bef25e4e1099c2838b43b4c9e Mon Sep 17 00:00:00 2001 From: tavo-wasd Date: Mon, 29 May 2023 23:22:15 -0600 Subject: [PATCH] pimping navigation --- bashrc | 61 +++++++++++++++--------------------- scripts/p | 12 +++++++ vim/view/~=+.config=+bashrc= | 31 ++++++++++++++++++ vim/vimrc | 4 +-- 4 files changed, 71 insertions(+), 37 deletions(-) create mode 100755 scripts/p create mode 100644 vim/view/~=+.config=+bashrc= diff --git a/bashrc b/bashrc index 1fc1639..3fcd640 100644 --- a/bashrc +++ b/bashrc @@ -1,6 +1,5 @@ #!/bin/bash # tavo custom bashrc file - # If not running interactively, don't do anything [[ $- != *i* ]] && return @@ -42,9 +41,12 @@ alias \ vid="cd $HOME/Videos/ && ls" \ mus="cd $HOME/Music/ && ls" \ ent="cd /mnt/Entr/ && ls" \ + fzfscripts="fzf_nav /home/$(whoami)/.config/scripts" \ ls="exa -al --group-directories-first" \ + fzf="fzf --cycle --reverse" \ diff="diff --color=auto" \ grep="grep --color=auto" \ + notes="note list" \ def="dict" \ calc="bc -l" \ cp="cp -iv" \ @@ -58,11 +60,11 @@ export \ QT_QPA_PLATFORMTHEME="qt6ct" \ DATE=$(date -I) \ -# Clipboard config +# DE opts +# Clipboard export \ CM_SELECTIONS="clipboard" \ CM_MAX_CLIPS=10 \ - # Default programs export \ OPENER="xdg-open" \ @@ -74,48 +76,37 @@ export \ IMAGE="sxiv" \ VIDEO="mpv" \ -# Functions -fzf_list_dir() { +# Functions & binds +fzf_nav() { +[ -d "$1" ] && cd "$1" # Fun POSIX way of listing stuff -for entry in * ; do - # If 'entry' is a directory, append '/' - test "${entry#*.*}" = "$entry" && entry="$entry/" - echo $entry -done | fzf +while true ; do + opt=$(for entry in * ; do + [ -d "$entry" ] && entry="$entry/" + [ "$entry" = "*" ] && entry="" + echo "$entry" + done) + opt=$(printf "../\n$opt" | fzf --cycle --reverse --padding 2% --preview 'p {}') + [ -d "$opt" ] && cd "$opt" > /dev/null 2>&1 || break +done +ls +[ -n "$opt" ] && printf "\nOpen $opt? [y/N]: " && read -r open || return 0 +[ "$open" = "y" ] && o "$opt" } +bind '"\C-n":"fzf_nav\C-m"' note() { # Just edit today's note if no argument is given [ -z "$1" ] && cd ~/Documents/notes && $EDITOR $HOME/Documents/notes/note-$DATE.md && exit -# 'list' arg will list notes wither with fzf or regular ls +# 'list' arg will list notes either with fzf or regular ls if [ "$1" = "list" ] ; then - cd ~/Documents/notes - # If fzf is present, list notes - if [ -e '/usr/bin/fzf' ] ; then - while test "${note#*.md}" = "$note" && cd "$note" && ; do - ls - done - note=$(fzf_list_dir) - # Regular ls otherwise - else ; ls - fi + cd ~/Documents/notes + # If fzf is present, use it, ls otherwise + [ -e '/usr/bin/fzf' ] || ls && fzf_nav fi } -follow() { # cd if found after 'which' command -[ -z "$1" ] && echo "Usage: follow " || - cd "$(which $1 | sed s/$1//g)" -} - -follow-edit() { # open in $EDITOR -[ -z "$1" ] && echo "Usage: follow " || - $EDITOR "$(which $1)" -} - -quitcd() { # cd into NNN's exported dir: Ctrl + G -cd $(grep -oP '"\K[^"\047]+(?=["\047])' ~/.config/nnn/.lastd) -} -bind '"\C-g":"quitcd\C-m"' +bind '"\C-e":"fzfscripts\C-m"' # Autostart dwm after tty login type systemctl 2>/dev/null 1>&2 && if systemctl -q is-active graphical.target && [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then diff --git a/scripts/p b/scripts/p new file mode 100755 index 0000000..b810f8d --- /dev/null +++ b/scripts/p @@ -0,0 +1,12 @@ +#!/bin/sh +# Preview files & dirs +file="$1" + +# If directory, list contents +[ -d "$file" ] && (cd "$file" && /usr/bin/ls -A1Fx --color --group-directories-first) + +case $file in + *.csv) column -s, -t < "$file" ;; + *.html) links -dump "$file" ;; + *) ! [ -d "$file" ] && head -n 47 "$file" && printf "\n\n ..." ;; +esac diff --git a/vim/view/~=+.config=+bashrc= b/vim/view/~=+.config=+bashrc= new file mode 100644 index 0000000..f109a2c --- /dev/null +++ b/vim/view/~=+.config=+bashrc= @@ -0,0 +1,31 @@ +let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1 +argglobal +setlocal fdm=manual +setlocal fde=0 +setlocal fmr={{{,}}} +setlocal fdi=# +setlocal fdl=0 +setlocal fml=1 +setlocal fdn=20 +setlocal fen +silent! normal! zE +6,8fold +10,15fold +17,27fold +29,55fold +57,61fold +63,77fold +79,109fold +111,117fold +let &fdl = &fdl +let s:l = 1 - ((0 * winheight(0) + 19) / 38) +if s:l < 1 | let s:l = 1 | endif +keepjumps exe s:l +normal! zt +keepjumps 1 +normal! 0 +let &g:so = s:so_save | let &g:siso = s:siso_save +set hlsearch +nohlsearch +doautoall SessionLoadPost +" vim: set ft=vim : diff --git a/vim/vimrc b/vim/vimrc index 807f4ff..d3a5d00 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -83,5 +83,5 @@ set noshowmode map gy :Goyo autocmd! User GoyoLeave highlight Normal ctermbg=NONE -autocmd BufWinLeave bibliography zM | mkview -autocmd BufWinEnter bibliography silent loadview +autocmd BufWinLeave bibliography,bashrc zM | mkview +autocmd BufWinEnter bibliography,bashrc silent loadview