Skip to content

Commit

Permalink
Tweak fish_function_path loading
Browse files Browse the repository at this point in the history
Change how the fish_function_path is modified to ensure there's no
duplicates even if the fish_function_path contained a path that matches
a repository's function path.

Force fish_function_path to be set globally to avoid issues if it was
originally set universally. This does not remove the universal variable,
but it does mean that once tacklebox is loaded, changes to the universal
variable won't affect the shell.
  • Loading branch information
lilyball committed Aug 31, 2014
1 parent 1c13cec commit ed77d84
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions tacklebox.fish
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,30 @@ function __tacklebox_prepend_path --no-scope-shadowing --description \
end
end

function __tacklebox_append_path --no-scope-shadowing --description \
'Append the given path, if it exists, to the specified path list (defaults to PATH)'
set -l path "$argv[1]"
set -l list PATH
if set -q argv[2]
set list $argv[2]
end

if test -d $path
# If the path is already in the list, skip it.
if not contains -- $path $$list
set -- $list $$list $path
end
end
end

###
# Configuration
###

# Standardize function path, to be restored later.
# Reset to just the datadir functions. At the end, we'll put the user
# functions back on front, and the sysconf functions on the end in front
# of the datadir functions, as is normally expected.
set -l user_function_path $fish_function_path
__tacklebox_strip_word "$__fish_sysconfdir/functions" user_function_path
set -l no_sysconf $status
__tacklebox_strip_word "$__fish_datadir/functions" user_function_path
set fish_function_path "$__fish_datadir/functions"
# Ensure the function path is global, not universal
set -g fish_function_path "$__fish_datadir/functions"

# Add all functions
for repository in $tacklebox_path[-1..1]
Expand All @@ -118,11 +129,14 @@ if test -n "$tacklebox_theme"
end

# Add back the user and sysconf functions as appropriate
set user_function_path $user_function_path $fish_function_path
__tacklebox_strip_word "$__fish_datadir/functions" user_function_path
__tacklebox_strip_word "$__fish_sysconfdir/functions" user_function_path # just in case
and set no_sysconf 0
if test $no_sysconf -eq 0
for path in $fish_function_path
# don't append either system path
if not contains -- "$path" "$__fish_sysconfdir/functions" "$__fish_datadir/functions"
__tacklebox_append_path $path user_function_path
end
end
if __tacklebox_strip_word "$__fish_sysconfdir/functions" user_function_path
set user_function_path $user_function_path "$__fish_sysconfdir/functions"
end
set fish_function_path $user_function_path "$__fish_datadir/functions"
__tacklebox_strip_word "$__fish_datadir/functions" user_function_path
set -g fish_function_path $user_function_path "$__fish_datadir/functions"

0 comments on commit ed77d84

Please sign in to comment.