Skip to content

Instantly share code, notes, and snippets.

@m-bers
Created February 27, 2021 22:54
Show Gist options
  • Save m-bers/3c84cd1a5309a8bfbfaf1cc8330ebdb6 to your computer and use it in GitHub Desktop.
Save m-bers/3c84cd1a5309a8bfbfaf1cc8330ebdb6 to your computer and use it in GitHub Desktop.
#!/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