Skip to content

Instantly share code, notes, and snippets.

@blackjack75
Created February 12, 2024 21:11
Show Gist options
  • Save blackjack75/d1a0a1fb3cc8b3cab015ef6130e982ea to your computer and use it in GitHub Desktop.
Save blackjack75/d1a0a1fb3cc8b3cab015ef6130e982ea to your computer and use it in GitHub Desktop.
Bash command to edit file with nvim with my user or sudo if necessary to write the file. Use config for my user with root (will download modules again)
#!/bin/bash
vv() {
if [ $# -eq 0 ]; then
echo "Usage: vv <file>"
echo "Will edit with current user or sudo if needed b ut using nvim config of this user"
return 1
fi
vpath=$(which $EDITOR)
cfg=$(realpath ~/.config/nvim/init.lua)
#Check if sudo is needed to edit the file
if [ -w "$1" ]; then
$vpath "$1"
else
sudo $vpath -u "$cfg" "$1"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment