Last active
May 26, 2021 10:04
-
-
Save jmickelin/c082900cd53b6fc0c49061bb4ca24ff6 to your computer and use it in GitHub Desktop.
Add a directory-specific function path for fish using direnv
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
# Note that this script runs in Bash! | |
# This appends the the subdirectory ./scripts/fish/functions to the $fish_function_path in the environment | |
# set up by direnv. | |
realpath.dirname() { REPLY=.; ! [[ $1 =~ /+[^/]+/*$|^//$ ]] || REPLY="${1%${BASH_REMATCH[0]}}"; REPLY=${REPLY:-/}; echo $REPLY; } | |
repo_fish_functions="$(realpath.dirname "$@")/scripts/fish/functions" | |
# Load fish shell and export its fish_function_path variable, appending the scripts one | |
# Note: This is exported as a colon separated string rather than an array (array exports are not a thing). | |
# In order to load it properly in fish, you need to tell fish that it is a path variable by adding | |
# the following to your config.fish: | |
# | |
# We also need to export it so that direnv can restore it properly once done. | |
# | |
# set -ax --path fish_function_path | |
# | |
direnv_load fish -lc 'set -ax --path fish_function_path "'$repo_fish_functions'"; export fish_function_path; direnv dump' | |
# Other commands go here, e.g. | |
use nix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment