Skip to content

Instantly share code, notes, and snippets.

@stevegt
Created December 20, 2025 03:13
Show Gist options
  • Select an option

  • Save stevegt/cfd70b07f1ec8d78d13f4358ce5933c8 to your computer and use it in GitHub Desktop.

Select an option

Save stevegt/cfd70b07f1ec8d78d13f4358ce5933c8 to your computer and use it in GitHub Desktop.
a script that i use to manage neovim shada files and start neovim accordingly
#!/bin/bash
# if -c flag is present, then use/create shada file in the current directory
if [ "$1" == "-c" ]
then
usecurdir=1
shift
fi
fn=nv.shada
dir=$PWD
curdir=$PWD
while true
do
path=$dir/$fn
if [ -e $path ]
then
# open old shada in parent directory
break
fi
if [ "$dir" == "/" ] || [ "$dir" == "$HOME" ] || [ "$usecurdir" == 1 ]
then
# create new shada in current directory
path=$curdir/$fn
touch $path
break
fi
# try parent directory
dir=$(dirname $dir)
done
# resume from shada, jump to most recent cursor position
exec nvim -i $path "+'0" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment