Last active
December 21, 2015 16:59
-
-
Save lee-dohm/6337324 to your computer and use it in GitHub Desktop.
Code for article 'Shells and Scripting'
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
set --local bin_index (contains --index /usr/bin $PATH) | |
set --local local_bin_index (contains --index /usr/local/bin $PATH) | |
if test $local_bin_index -gt $bin_index | |
set --erase $PATH[$local_bin_index] | |
set --local local_path '' | |
if test (math $bin_index - 1) -gt 0 | |
set local_path $PATH[1..(math $bin_index - 1)] | |
end | |
set local_path $local_path /usr/local/bin | |
set local_path $local_path $PATH[$bin_index..-1] | |
set --global --export PATH $local_path | |
end |
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
path = ENV['PATH'].split(/:/) | |
bin_index = path.find_index('/usr/bin') | |
local_bin_index = path.find_index('/usr/local/bin') | |
if local_bin_index > bin_index | |
path.delete_at(local_bin_index) | |
path.insert(bin_index, '/usr/local/bin') | |
ENV['PATH'] = path | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment