Skip to content

Instantly share code, notes, and snippets.

@benkrikler
Last active February 26, 2020 10:29
Show Gist options
  • Save benkrikler/69df94f360629afa4cd5c36cbc46fc5e to your computer and use it in GitHub Desktop.
Save benkrikler/69df94f360629afa4cd5c36cbc46fc5e to your computer and use it in GitHub Desktop.
Bash function to open a given "PATH" variable (PATH, LD_LIBRARY_PATH, PYTHONPATH, etc) in an editor with each field on one line, then reassemble the path with colon separators
edit_path ()
{
local tmpfile=$(mktemp);
local variable="${1:-PATH}";
tr ':' '\n' <<< "${!variable}" > "$tmpfile";
"$EDITOR" "$tmpfile";
export ${variable}="$(tr '\n' : < "$tmpfile"| sed -e 's/:$//' )"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment