diff --git a/.gitignore b/.gitignore index 8c2835b..8448d45 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -!/tests/**/.local-sherpa +!/tests/**/.sherparc diff --git a/README.md b/README.md index 5496d4c..7cd2373 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ function_1() { ``` ```shell -# ~/projects/project_awesome/.local-sherpa +# ~/projects/project_awesome/.sherparc export VAR_1="LOCAL VAR PROJECT AWESOME" alias alias_1='echo "LOCAL ALIAS PROJECT AWESOME"' @@ -77,7 +77,7 @@ Sherpa won't load any local env file unless you trust the directory first. This is to prevent running malicious code when you `cd` into a directory. ``` bash -$ echo "alias rs=rspec" > ~/projects/project_awesome/.local-sherpa +$ echo "alias rs=rspec" > ~/projects/project_awesome/.sherparc $ cd ~/projects/project_awesome Sherpa: The local env file is not trusted. Run `sherpa trust` to mark it as trusted. $ rs @@ -123,8 +123,8 @@ Unexported variables and other data types are not supported yet. $ git clone git@github.com:tothpeter/local_sherpa.git ~/.dotfiles/lib/local_sherpa # Hook it into your shell $ echo "source ~/.dotfiles/lib/local_sherpa/local_sherpa.sh" >> ~/.zshrc -# Exclude the local env Sherpa files (.local-sherpa) globally in Git -$ echo ".local-sherpa" >> $(git config --global core.excludesfile) +# Exclude the local env Sherpa files (.sherparc) globally in Git +$ echo ".sherparc" >> $(git config --global core.excludesfile) # Optional but recommended alias se='sherpa edit' @@ -145,8 +145,8 @@ if you find it useful. ```shell # Given the following directory structure with the corresponding local env files -# ~/projects/.local-sherpa -# ~/projects/project_awesome/.local-sherpa +# ~/projects/.sherparc +# ~/projects/project_awesome/.sherparc # ~/projects/project_awesome/subdir $ cd ~/projects/ @@ -183,7 +183,9 @@ Sherpa: Local env loaded. Sherpa is ready for action. ### Local env file -🚧 Comming up +```shell +export SHERPA_LOCAL_ENV_FILE='.sherparc' +``` ## Cookbook @@ -192,7 +194,7 @@ Sherpa: Local env loaded. Sherpa is ready for action. ```shell # Run RSpec in the `project-awesome-api` Docker container -# ~/projects/project_awesome_api/.local-sherpa +# ~/projects/project_awesome_api/.sherparc alias de='docker exec -it project-awesome-api' alias rs='de rspec' ``` @@ -200,7 +202,7 @@ alias rs='de rspec' ```shell # Run RSpec on the host machine -# ~/projects/project_for_mortals/.local-sherpa +# ~/projects/project_for_mortals/.sherparc alias rs='bin/rspec' ``` @@ -209,21 +211,21 @@ With this config `RSpec` will run depending on in which directory you `cd` into. ### Rails console in production 🤫 ```shell -# ~/projects/project_with_heroku/.local-sherpa +# ~/projects/project_with_heroku/.sherparc alias rc_prod='heroku run rails c -a APP_NAME' -# ~/projects/project_with_aws/.local-sherpa +# ~/projects/project_with_aws/.sherparc alias rc_prod='ssh -i /path/key-pair-name.pem user@hostname "/var/app/current/bin/rails console"' ``` ### Start your dev environment ```shell -# ~/projects/project_with_docker/.local-sherpa +# ~/projects/project_with_docker/.sherparc alias up='docker-compose up --build -d' alias down='docker-compose down' -# ~/projects/project_basic/.local-sherpa +# ~/projects/project_basic/.sherparc alias up='bin/rails s' ``` diff --git a/lib/init.sh b/lib/init.sh index e7d0a24..87fec91 100644 --- a/lib/init.sh +++ b/lib/init.sh @@ -1,5 +1,6 @@ export SHERPA_ENABLED=true export SHERPA_LOG_LEVEL='info' # debug, info, no talking +export SHERPA_LOCAL_ENV_FILE='.sherparc' if [ -n "$ZSH_VERSION" ]; then SHERPA_LIB_PATH=$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P ) diff --git a/lib/local_env_file_parser.sh b/lib/local_env_file_parser.sh index b220771..5698382 100644 --- a/lib/local_env_file_parser.sh +++ b/lib/local_env_file_parser.sh @@ -10,7 +10,7 @@ _fetch_variable_names() { # Cleanup: # export var_1 -> var_1 local variable_names - variable_names=$(grep -oE "$filter_pattern" .local-sherpa | awk '{print $2}') + variable_names=$(grep -oE "$filter_pattern" "$SHERPA_LOCAL_ENV_FILE" | awk '{print $2}') if [ -n "$variable_names" ]; then echo "$variable_names" @@ -23,7 +23,7 @@ _fetch_aliase_names() { # Cleanup: # alias alias_1=... -> alias_1 local alias_names - alias_names=$(grep -E "$filter_pattern" .local-sherpa | awk -F'[ =]' '{print $2}') + alias_names=$(grep -E "$filter_pattern" "$SHERPA_LOCAL_ENV_FILE" | awk -F'[ =]' '{print $2}') if [ -n "$alias_names" ]; then echo "$alias_names" @@ -37,7 +37,7 @@ _fetch_function_names() { # function_1() -> function_1 # function function_2() -> function_2() -> function_2 local function_names - function_names=$(grep -oE "$filter_pattern" .local-sherpa | \ + function_names=$(grep -oE "$filter_pattern" "$SHERPA_LOCAL_ENV_FILE" | \ sed 's/function //' | \ sed 's/()//') diff --git a/lib/sherpa.sh b/lib/sherpa.sh index 76152ff..6d0f706 100644 --- a/lib/sherpa.sh +++ b/lib/sherpa.sh @@ -30,7 +30,7 @@ Tell sherpa how much he should talk (works only for the current session): edit() { echo "hint: Waiting for your editor to close the file..." - eval "$EDITOR .local-sherpa" + eval "$EDITOR $SHERPA_LOCAL_ENV_FILE" } disable() { @@ -107,7 +107,7 @@ load_current_env() { log_debug "Load local env?" # Skip if there is no local env file - [ -f .local-sherpa ] || { log_debug "No local env file"; return; } + [ -f "$SHERPA_LOCAL_ENV_FILE" ] || { log_debug "No local env file"; return; } # Skip if the env was already loaded was_env_loaded && { log_debug "Local env already loaded"; return; } @@ -117,8 +117,8 @@ load_current_env() { stash_local_env log_debug "Load local env" - # shellcheck disable=SC1091 - source .local-sherpa + # shellcheck disable=SC1090 + source "$SHERPA_LOCAL_ENV_FILE" # Append the current directory to the list. This is needed to unload the envs # in the right order when we change directories. The root directory should be # the last one to unload. diff --git a/lib/trust_verification.sh b/lib/trust_verification.sh index cd886bc..13ed457 100644 --- a/lib/trust_verification.sh +++ b/lib/trust_verification.sh @@ -1,7 +1,7 @@ #!/bin/bash _calculate_checksum() { - sha256sum .local-sherpa | cut -d ' ' -f 1 + sha256sum "$SHERPA_LOCAL_ENV_FILE" | cut -d ' ' -f 1 } verify_trust() { @@ -31,7 +31,7 @@ verify_trust() { } trust_current_env() { - if [[ ! -f .local-sherpa ]]; then + if [[ ! -f "$SHERPA_LOCAL_ENV_FILE" ]]; then log_info "Nothing to trust. The current directory has no local env file. Run \`sherpa edit\` to create one." return 1 fi diff --git a/tests/fixtures/parsing/.local-sherpa b/tests/fixtures/parsing/.sherparc similarity index 100% rename from tests/fixtures/parsing/.local-sherpa rename to tests/fixtures/parsing/.sherparc diff --git a/tests/lib/local_env_file_parser_test.sh b/tests/lib/local_env_file_parser_test.sh index dd2ca36..016ad47 100644 --- a/tests/lib/local_env_file_parser_test.sh +++ b/tests/lib/local_env_file_parser_test.sh @@ -1,7 +1,7 @@ source tests/support/init.sh # Setup -cd fixtures/parsing +export SHERPA_LOCAL_ENV_FILE="fixtures/parsing/$SHERPA_LOCAL_ENV_FILE" expected_list="var_1 diff --git a/tests/playground/performance/.local-sherpa b/tests/playground/performance/.sherparc similarity index 100% rename from tests/playground/performance/.local-sherpa rename to tests/playground/performance/.sherparc diff --git a/tests/playground/project_1/.local-sherpa b/tests/playground/project_1/.sherparc similarity index 100% rename from tests/playground/project_1/.local-sherpa rename to tests/playground/project_1/.sherparc diff --git a/tests/playground/project_1/subfolder/subproject/.local-sherpa b/tests/playground/project_1/subfolder/subproject/.sherparc similarity index 100% rename from tests/playground/project_1/subfolder/subproject/.local-sherpa rename to tests/playground/project_1/subfolder/subproject/.sherparc diff --git a/tests/playground/project_2/.local-sherpa b/tests/playground/project_2/.sherparc similarity index 100% rename from tests/playground/project_2/.local-sherpa rename to tests/playground/project_2/.sherparc