Last active
November 18, 2019 20:02
-
-
Save bastnic/a32d07160bedd50de3c9d167e2377041 to your computer and use it in GitHub Desktop.
nvalt rewrite in bash and vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! s:goyo_enter() | |
let b:quitting = 0 | |
let b:quitting_bang = 0 | |
autocmd QuitPre <buffer> let b:quitting = 1 | |
cabbrev <buffer> q! let b:quitting_bang = 1 <bar> q! | |
endfunction | |
function! s:goyo_leave() | |
" Quit Vim if this is the only remaining buffer | |
if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1 | |
if b:quitting_bang | |
qa! | |
else | |
qa | |
endif | |
endif | |
endfunction | |
autocmd! User GoyoEnter call <SID>goyo_enter() | |
autocmd! User GoyoLeave call <SID>goyo_leave() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
main() { | |
file_to_edit=`select_file` | |
if [ -n "$file_to_edit" ] ; then | |
"$EDITOR" "+Goyo" "$file_to_edit" | |
main "$file_to_edit" | |
fi | |
} | |
select_file() { | |
given_file="$1" | |
output=`ls -t | fzf --no-sort --preview="bat --theme=TwoDark --color=always {}" --preview-window=right:70%:wrap --color=light --print-query --query="$given_file"` | |
if [ $? -eq 1 ] ; then | |
echo "$output" | |
else | |
echo "$output" | tail -n 1 | |
fi | |
} | |
main "" |
Dependencies:
Use it with:
alias nvalt='cd ~/Documents/notes/ && ~/.bin/nvalt.sh && cd -'
just tap nvalt
in the shell open all my files inside this folder (voluntarly at the same level, but could be recursive).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍