Skip to content

Commit

Permalink
Merge pull request #23 from gianluca-mascolo/make-version
Browse files Browse the repository at this point in the history
make version
  • Loading branch information
gianluca-mascolo authored Oct 11, 2023
2 parents 23e42a1 + 5dad1f0 commit 861a519
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
README.md.backup
./tests/profiles/ephemeral.profile
*.tar.gz
/.version
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ clean:

.PHONY: install
install:
ifneq ("$(wildcard .version)","")
install -m 0644 -C .version $(PROFILE_DIRECTORY)/.version
endif
install -m 0644 -C bash_profile_switcher.sh $(INSTALL_PATH)/.bash_profile_switcher
ifneq ("$(BASHRC_INSTALL_STATUS)","0")
$(file >> $(BASHRC_PATH),$())
Expand All @@ -57,4 +60,5 @@ install-snippets:

.PHONY: release
release: $(PACKAGE_FILES)
echo 'export SWITCH_PROFILE_VERSION=$(VERSION)' > .version
tar --transform='s,,$(PACKAGE_NAME)_$(VERSION)/,' -czf $(PACKAGE_NAME)_$(VERSION).tar.gz $(PACKAGE_FILES)
10 changes: 9 additions & 1 deletion bash_profile_switcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export SWITCH_PROFILE_SAVED=".bash_saved_profile"
# snipname1:snipname2:snippetname3
export SWITCH_PROFILE_SNIPPETS=""

# shellcheck source=/dev/null
[[ -f "$HOME/$SWITCH_PROFILE_DIRECTORY/.version" ]] && source "$HOME/$SWITCH_PROFILE_DIRECTORY/.version"
# _switch_profile_parse
# To be used with mapfile
# Every line in the file is parsed and checked for a corresponding snippet to be loaded
Expand Down Expand Up @@ -118,6 +120,8 @@ OPTIONS
Temporary profile. Load selected profile in current shell without starting it in new bash shells
-l
List available profiles
-v
Display switch_profile version
-h Show help instructions (this help)
PROFILE
Expand Down Expand Up @@ -164,7 +168,7 @@ switch_profile() {
KEEP_ENV=0
TEMP_PROFILE=0
RESET_PROFILE=0
while getopts ":tkdhl" Option; do
while getopts ":tkdhlv" Option; do
case $Option in
k)
KEEP_ENV=1
Expand All @@ -183,6 +187,10 @@ switch_profile() {
_switch_profile_help
return 0
;;
v)
echo "${SWITCH_PROFILE_VERSION:-unknown}"
return 0
;;
d)
RESET_PROFILE=1
;;
Expand Down
1 change: 1 addition & 0 deletions tests/automated_tests.exp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ source ./tests/scenarios/07-keep-profile.exp
source ./tests/scenarios/08-unexistent-profile.exp
source ./tests/scenarios/09-reload-list.exp
source ./tests/scenarios/10-check-snippet.exp
source ./tests/scenarios/11-check-version.exp

sleep 1
send "exit\n"
Expand Down
1 change: 1 addition & 0 deletions tests/profiles/.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export SWITCH_PROFILE_VERSION=testver
10 changes: 10 additions & 0 deletions tests/scenarios/11-check-version.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set scenario_results($scenario_index) "FAIL - Check version"

send "echo \${SWITCH_PROFILE_VERSION}\n"
expect {
timeout abort
"testver"
}

set scenario_results($scenario_index) "PASS - Check version"
set scenario_index [ expr $scenario_index + 1]

0 comments on commit 861a519

Please sign in to comment.