Created
February 12, 2024 21:11
-
-
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)
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
#!/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