Created
February 27, 2021 22:54
-
-
Save m-bers/3c84cd1a5309a8bfbfaf1cc8330ebdb6 to your computer and use it in GitHub Desktop.
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 | |
# This is a simple script that will allow you to edit non-owned/writable files with vscode without running vscode as sudo | |
# I put it in /home/$USER/bin/sudocode (run "source ~/.profile" to add ~/bin to your PATH) | |
{ | |
sourcepermissions=$(stat --format '%a' $1); \ | |
sourceuser=$(stat -c '%U' $1); \ | |
sourcegroup=$(stat -c '%G' $1); \ | |
sudo chmod 777 $1; \ | |
sudo chown "${USER}:${USER}" $1; \ | |
code -w $1; \ | |
sudo chown "${sourceuser}:${sourcegroup}" $1; \ | |
sudo chmod $sourcepermissions $1; \ | |
} & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment