From 03a71a4e94e1a095b8a3ec8a92cf64c31aaa6a7a Mon Sep 17 00:00:00 2001 From: Pierre Hyvernat Date: Tue, 29 Jun 2021 11:53:51 +0200 Subject: [PATCH] renaming of files and dirs to be more consistent GSH_ROOT/bin => GSH_ROOT/scripts previous_commands.sh => fc-lnr.sh history_start.sh / history_clean.sh => alt_history_start.sh / alt_history_stop.sh realpath => readlink-f save_environment.sh => print_current_environment.sh --- Makefile | 2 +- lib/bin_test.sh | 18 +++++++++--------- lib/gsh.sh | 4 ++-- lib/gshrc | 2 +- lib/mission_source.sh | 8 ++++---- lib/profile.sh | 4 ++-- missions/basic/01_cd_tower/check.sh | 4 ++-- missions/basic/02_cd.._cellar/check.sh | 4 ++-- missions/basic/03_cd_HOME_throne/auto.sh | 4 ++-- missions/basic/03_cd_HOME_throne/check.sh | 6 +++--- missions/basic/03_cd_HOME_throne/test.sh | 4 ++-- missions/finding_files_maze/01_ls_cd/init.sh | 2 +- missions/finding_files_maze/02_tree/init.sh | 2 +- missions/finding_files_maze/03_find_1/init.sh | 2 +- missions/finding_files_maze/04_find_2/init.sh | 2 +- .../05_find_xargs_grep/init.sh | 2 +- .../intermediate/02_alias_journal/check.sh | 4 ++-- .../intermediate/03_tab_spider_lair/check.sh | 2 +- missions/intermediate/04_bg_xeyes/auto.sh | 4 ++-- missions/intermediate/04_bg_xeyes/check.sh | 2 +- missions/intermediate/04_bg_xeyes/test.sh | 4 ++-- .../01_chmod_x_dir_king_quarter/check.sh | 2 +- .../01_chmod_x_dir_king_quarter/clean.sh | 4 ++-- .../01_chmod_x_dir_king_quarter/init.sh | 2 +- .../03_chmod_rw_file_dir_throne_room/clean.sh | 4 ++-- .../pipe_intro_book_of_potions/01_head/auto.sh | 4 ++-- .../01_head/check.sh | 6 +++--- .../pipe_intro_book_of_potions/01_head/test.sh | 4 ++-- .../pipe_intro_book_of_potions/02_tail/auto.sh | 4 ++-- .../02_tail/check.sh | 6 +++--- .../pipe_intro_book_of_potions/02_tail/test.sh | 4 ++-- .../pipe_intro_book_of_potions/03_cat/auto.sh | 4 ++-- .../pipe_intro_book_of_potions/03_cat/check.sh | 6 +++--- .../pipe_intro_book_of_potions/03_cat/test.sh | 4 ++-- .../pipe_intro_book_of_potions/04_pipe/auto.sh | 4 ++-- .../04_pipe/check.sh | 6 +++--- .../pipe_intro_book_of_potions/04_pipe/test.sh | 4 ++-- .../05_pipe_head_tail/auto.sh | 4 ++-- .../05_pipe_head_tail/check.sh | 6 +++--- .../05_pipe_head_tail/test.sh | 4 ++-- .../04_stderr_dev-null_grimoires/auto.sh | 4 ++-- .../04_stderr_dev-null_grimoires/check.sh | 3 ++- {bin => scripts}/RANDOM | 0 {bin => scripts}/_gsh_HELP | 0 {bin => scripts}/_gsh_goal | 0 {bin => scripts}/_gsh_help | 0 {bin => scripts}/_gsh_index | 0 {bin => scripts}/_gsh_log | 4 ++-- {bin => scripts}/_gsh_log.awk | 0 {bin => scripts}/_gsh_pcm | 0 {bin => scripts}/_gsh_protect | 0 {bin => scripts}/_gsh_stat | 4 ++-- {bin => scripts}/_gsh_stat.awk | 0 {bin => scripts}/_gsh_systemconfig | 0 {bin => scripts}/_gsh_unprotect | 0 {bin => scripts}/_gsh_welcome | 0 {bin => scripts}/admin_mode | 0 .../alt_history_start.sh | 6 +++--- .../alt_history_stop.sh | 6 +++--- {bin => scripts}/box.awk | 0 {bin => scripts}/box.sh | 0 {bin => scripts}/check_file | 0 {bin => scripts}/checksum | 0 {bin => scripts}/color_echo | 0 {bin => scripts}/copy_bin | 0 {bin => scripts}/create_boxes_data.awk | 0 bin/previous_commands.sh => scripts/fc-lnr.sh | 11 +++++++++-- {bin => scripts}/generate_rcfile | 0 {bin => scripts}/gsh_gettext.sh | 0 {bin => scripts}/mainshell.sh | 0 {bin => scripts}/make_index | 6 +++--- {bin => scripts}/missiondir | 2 +- {bin => scripts}/missionname | 2 +- {bin => scripts}/pager | 0 {bin => scripts}/parchment | 0 .../print_current_environment.sh | 0 {bin => scripts}/progress_bar | 0 {bin => scripts}/progress_bar.sh | 1 + {bin => scripts}/random_string | 0 bin/realpath => scripts/readlink-f | 0 {bin => scripts}/reflow.awk | 0 {bin => scripts}/sed-i | 0 {bin => scripts}/seq | 0 {bin => scripts}/sign_file | 0 {bin => scripts}/textdomainname | 2 +- {bin => scripts}/treasure_message | 2 +- start.sh | 5 ++--- tests/test-history.sh | 8 ++++---- utils/archive.sh | 4 ++-- 89 files changed, 123 insertions(+), 115 deletions(-) rename {bin => scripts}/RANDOM (100%) rename {bin => scripts}/_gsh_HELP (100%) rename {bin => scripts}/_gsh_goal (100%) rename {bin => scripts}/_gsh_help (100%) rename {bin => scripts}/_gsh_index (100%) rename {bin => scripts}/_gsh_log (80%) rename {bin => scripts}/_gsh_log.awk (100%) rename {bin => scripts}/_gsh_pcm (100%) rename {bin => scripts}/_gsh_protect (100%) rename {bin => scripts}/_gsh_stat (72%) rename {bin => scripts}/_gsh_stat.awk (100%) rename {bin => scripts}/_gsh_systemconfig (100%) rename {bin => scripts}/_gsh_unprotect (100%) rename {bin => scripts}/_gsh_welcome (100%) rename {bin => scripts}/admin_mode (100%) rename bin/history_start.sh => scripts/alt_history_start.sh (79%) rename bin/history_clean.sh => scripts/alt_history_stop.sh (77%) rename {bin => scripts}/box.awk (100%) rename {bin => scripts}/box.sh (100%) rename {bin => scripts}/check_file (100%) rename {bin => scripts}/checksum (100%) rename {bin => scripts}/color_echo (100%) rename {bin => scripts}/copy_bin (100%) rename {bin => scripts}/create_boxes_data.awk (100%) rename bin/previous_commands.sh => scripts/fc-lnr.sh (78%) rename {bin => scripts}/generate_rcfile (100%) rename {bin => scripts}/gsh_gettext.sh (100%) rename {bin => scripts}/mainshell.sh (100%) rename {bin => scripts}/make_index (96%) rename {bin => scripts}/missiondir (95%) rename {bin => scripts}/missionname (96%) rename {bin => scripts}/pager (100%) rename {bin => scripts}/parchment (100%) rename bin/save_environment.sh => scripts/print_current_environment.sh (100%) rename {bin => scripts}/progress_bar (100%) rename {bin => scripts}/progress_bar.sh (99%) rename {bin => scripts}/random_string (100%) rename bin/realpath => scripts/readlink-f (100%) rename {bin => scripts}/reflow.awk (100%) rename {bin => scripts}/sed-i (100%) rename {bin => scripts}/seq (100%) rename {bin => scripts}/sign_file (100%) rename {bin => scripts}/textdomainname (51%) rename {bin => scripts}/treasure_message (93%) diff --git a/Makefile b/Makefile index 1a2991a2..e94890fa 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ tests-verbose: clean ./"game shell (1).sh" -RDq -c 'gsh systemconfig; for _ in $$(seq 42); do gsh goal|cat; gsh test --abort; gsh auto --abort; done; gsh stat' clean: - rm -rf i18n/*~ locale gameshell.tgz gameshell.sh gameshell-save.sh bin/boxes-data.awk + rm -rf i18n/*~ locale gameshell.tgz gameshell.sh gameshell-save.sh scripts/boxes-data.awk rm -rf .bin .config .sbin .var World rm -rf "game shell"* diff --git a/lib/bin_test.sh b/lib/bin_test.sh index 307d9417..1895c1a8 100644 --- a/lib/bin_test.sh +++ b/lib/bin_test.sh @@ -1,6 +1,6 @@ #!/bin/sh -### test the various utilities in GSH_ROOT/bin/ directory +### test the various utilities in GSH_ROOT/scripts/ directory test_mktemp() ( if ! tmp=$(mktemp 2>/dev/null) @@ -17,33 +17,33 @@ test_mktemp() ( ) -test_realpath() ( +test_readlink_f() ( tmp=${GSH_TMP:?Error: \$GSH_TMP not set} cd "$tmp" rm -f a b touch a - rpa=$(realpath ./a) + rpa=$(readlink-f ./a) if [ -z "$rpa" ] then - echo "Error: realpath returned the empty string." >&2 + echo "Error: readlink-f returned the empty string." >&2 return 1 fi case "$rpa" in - "$(realpath "$tmp")"* ) + "$(readlink-f "$tmp")"* ) ;; * ) - echo "Error: realpath didn't give an absolute path." >&2 + echo "Error: readlink-f didn't give an absolute path." >&2 return 1 ;; esac ln -s a b - rpb=$(realpath b) + rpb=$(readlink-f b) if [ "$rpa" != "$rpb" ] then - echo "Error: realpath doesn't resolve symbolic links." >&2 + echo "Error: readlink-f doesn't resolve symbolic links." >&2 return 1 fi @@ -97,4 +97,4 @@ test_sign() ( return 0 ) -test_mktemp && test_realpath && test_checksum && test_sign +test_mktemp && test_readlink_f && test_checksum && test_sign diff --git a/lib/gsh.sh b/lib/gsh.sh index 72572a65..20827d53 100644 --- a/lib/gsh.sh +++ b/lib/gsh.sh @@ -194,7 +194,7 @@ __gsh_start() { then local env_before=$(mktemp) local env_after=$(mktemp) - . save_environment.sh > "$env_before" + . print_current_environment.sh > "$env_before" fi mission_source "$MISSION_DIR/init.sh" @@ -221,7 +221,7 @@ Aborting.")" >&2 if ! . mainshell.sh then - . save_environment.sh > "$env_after" + . print_current_environment.sh > "$env_after" if ! cmp -s "$env_before" "$env_after" then diff --git a/lib/gshrc b/lib/gshrc index 60f56fed..21497958 100644 --- a/lib/gshrc +++ b/lib/gshrc @@ -23,7 +23,7 @@ export COLUMNS # choose appropriate pager unset PAGER tempfile=$(mktemp) -echo "TEST" | "$GSH_ROOT/bin/pager" 2>"$tempfile" >/dev/null +echo "TEST" | "$GSH_ROOT/scripts/pager" 2>"$tempfile" >/dev/null if [ -s "$tempfile" ] then export PAGER=more diff --git a/lib/mission_source.sh b/lib/mission_source.sh index 8fcf916c..1e1fd565 100644 --- a/lib/mission_source.sh +++ b/lib/mission_source.sh @@ -44,7 +44,7 @@ mission_source() { local _MISSION_DIR _TEXTDOMAIN _MISSION_NAME _PATH exit_status export MISSION_DIR TEXTDOMAIN MISSION_NAME _MISSION_DIR=$MISSION_DIR - MISSION_DIR=$(dirname "$(realpath "$FILENAME")") + MISSION_DIR=$(dirname "$(readlink-f "$FILENAME")") _TEXTDOMAIN=$TEXTDOMAIN TEXTDOMAIN=$(textdomainname "$MISSION_DIR") _MISSION_NAME=$MISSION_NAME @@ -75,9 +75,9 @@ mission_source() { # otherwise, record the environment (variables, functions and aliases) # before and after to echo a message when there are differences - . save_environment.sh >"$env_before" + . print_current_environment.sh >"$env_before" _MISSION_DIR=$MISSION_DIR - MISSION_DIR=$(dirname "$(realpath "$FILENAME")") + MISSION_DIR=$(dirname "$(readlink-f "$FILENAME")") _TEXTDOMAIN=$TEXTDOMAIN TEXTDOMAIN=$(textdomainname "$MISSION_DIR") _MISSION_NAME=$MISSION_NAME @@ -90,7 +90,7 @@ mission_source() { MISSION_NAME=$_MISSION_NAME MISSION_DIR=$_MISSION_DIR PATH=$_PATH - . save_environment.sh | grep -v "$MISSION_FN" > "$env_after" + . print_current_environment.sh | grep -v "$MISSION_FN" > "$env_after" if ! cmp -s "$env_before" "$env_after" then diff --git a/lib/profile.sh b/lib/profile.sh index c45f2c32..c04eb8e0 100644 --- a/lib/profile.sh +++ b/lib/profile.sh @@ -30,6 +30,6 @@ export COLUMNS # putting $GSH_ROOT/bin first makes sure the local scripts are prefered over # system commands (realpath, seq, etc.). This is useful for testing, but # probably shouldn't be done for "stable" releases. -PATH="$GSH_ROOT/bin":$PATH -# PATH=$PATH:"$GSH_ROOT/bin" +PATH="$GSH_ROOT/scripts":$PATH +# PATH=$PATH:"$GSH_ROOT/scripts" diff --git a/missions/basic/01_cd_tower/check.sh b/missions/basic/01_cd_tower/check.sh index 7234f0fa..c76e7c87 100644 --- a/missions/basic/01_cd_tower/check.sh +++ b/missions/basic/01_cd_tower/check.sh @@ -1,7 +1,7 @@ #!/bin/sh -goal=$(realpath "$(eval_gettext "\$GSH_HOME/Castle/Main_tower/First_floor/Second_floor/Top_of_the_tower")") -current=$(realpath "$PWD") +goal=$(readlink-f "$(eval_gettext "\$GSH_HOME/Castle/Main_tower/First_floor/Second_floor/Top_of_the_tower")") +current=$(readlink-f "$PWD") if [ "$goal" = "$current" ] then diff --git a/missions/basic/02_cd.._cellar/check.sh b/missions/basic/02_cd.._cellar/check.sh index 90a719a9..f49e6eaf 100644 --- a/missions/basic/02_cd.._cellar/check.sh +++ b/missions/basic/02_cd.._cellar/check.sh @@ -1,7 +1,7 @@ #!/bin/sh -goal=$(realpath "$(eval_gettext "\$GSH_HOME/Castle/Cellar")") -current=$(realpath "$PWD") +goal=$(readlink-f "$(eval_gettext "\$GSH_HOME/Castle/Cellar")") +current=$(readlink-f "$PWD") if [ "$goal" = "$current" ] then diff --git a/missions/basic/03_cd_HOME_throne/auto.sh b/missions/basic/03_cd_HOME_throne/auto.sh index 6125c4c7..d43e9dc1 100644 --- a/missions/basic/03_cd_HOME_throne/auto.sh +++ b/missions/basic/03_cd_HOME_throne/auto.sh @@ -1,6 +1,6 @@ #!/bin/sh -. history_start.sh +. alt_history_start.sh cd "$(eval_gettext '$GSH_HOME/Castle/Main_building/Throne_room')" @@ -11,4 +11,4 @@ add_cmd cd "$(eval_gettext '$GSH_HOME/Castle/Main_building/Throne_room')" add_cmd gsh check gsh check -. history_clean.sh +. alt_history_stop.sh diff --git a/missions/basic/03_cd_HOME_throne/check.sh b/missions/basic/03_cd_HOME_throne/check.sh index 930b4dc4..0ade138b 100644 --- a/missions/basic/03_cd_HOME_throne/check.sh +++ b/missions/basic/03_cd_HOME_throne/check.sh @@ -3,10 +3,10 @@ # this should be POSIX compliant, but debian's sh (dash) doesn't have fc! _mission_check() { - goal=$(realpath "$(eval_gettext "\$GSH_HOME/Castle/Main_building/Throne_room")") - current=$(realpath "$PWD") + goal=$(readlink-f "$(eval_gettext "\$GSH_HOME/Castle/Main_building/Throne_room")") + current=$(readlink-f "$PWD") - ppc=$(. previous_commands.sh | sed -n '2p;3q') + ppc=$(. fc-lnr.sh | sed -n '2p;3q') # FIXME: also accept other commands to go back to the starting point? # FIXME: add an error message diff --git a/missions/basic/03_cd_HOME_throne/test.sh b/missions/basic/03_cd_HOME_throne/test.sh index 9b3ed41d..dc79b27c 100644 --- a/missions/basic/03_cd_HOME_throne/test.sh +++ b/missions/basic/03_cd_HOME_throne/test.sh @@ -1,6 +1,6 @@ #!/bin/sh -. history_start.sh +. alt_history_start.sh # add dummy commands to avoid error messages add_cmd dummy1 @@ -30,4 +30,4 @@ add_cmd cd "$(eval_gettext '$GSH_HOME/Castle/Main_building/Throne_room')" add_cmd gsh check gsh assert check true -. history_clean.sh +. alt_history_stop.sh diff --git a/missions/finding_files_maze/01_ls_cd/init.sh b/missions/finding_files_maze/01_ls_cd/init.sh index 231899e4..501630fc 100644 --- a/missions/finding_files_maze/01_ls_cd/init.sh +++ b/missions/finding_files_maze/01_ls_cd/init.sh @@ -6,7 +6,7 @@ mkdir -p "$GSH_CHEST" _mission_init() ( if ! command -v generate_maze.sh >/dev/null then - DUMMY_MISSION=$(realpath "$MISSION_DIR/../00_shared") + DUMMY_MISSION=$(readlink-f "$MISSION_DIR/../00_shared") DUMMY_MISSION=${DUMMY_MISSION#$GSH_MISSIONS/} echo "$(eval_gettext "Dummy mission '\$DUMMY_MISSION' is required for mission \$MISSION_NB (\$MISSION_NAME).")" >&2 return 1 diff --git a/missions/finding_files_maze/02_tree/init.sh b/missions/finding_files_maze/02_tree/init.sh index 727dcf52..6c658903 100644 --- a/missions/finding_files_maze/02_tree/init.sh +++ b/missions/finding_files_maze/02_tree/init.sh @@ -6,7 +6,7 @@ mkdir -p "$GSH_CHEST" _mission_init() ( if ! command -v generate_maze.sh >/dev/null then - DUMMY_MISSION=$(realpath "$MISSION_DIR/../00_shared") + DUMMY_MISSION=$(readlink-f "$MISSION_DIR/../00_shared") DUMMY_MISSION=${DUMMY_MISSION#$GSH_MISSIONS/} echo "$(eval_gettext "Dummy mission '\$DUMMY_MISSION' is required for mission \$MISSION_NB (\$MISSION_NAME).")" >&2 return 1 diff --git a/missions/finding_files_maze/03_find_1/init.sh b/missions/finding_files_maze/03_find_1/init.sh index 12759905..02dccbe2 100644 --- a/missions/finding_files_maze/03_find_1/init.sh +++ b/missions/finding_files_maze/03_find_1/init.sh @@ -6,7 +6,7 @@ mkdir -p "$GSH_CHEST" _mission_init() ( if ! command -v generate_maze.sh >/dev/null then - DUMMY_MISSION=$(realpath "$MISSION_DIR/../00_shared") + DUMMY_MISSION=$(readlink-f "$MISSION_DIR/../00_shared") DUMMY_MISSION=${DUMMY_MISSION#$GSH_MISSIONS/} echo "$(eval_gettext "Dummy mission '\$DUMMY_MISSION' is required for mission \$MISSION_NB (\$MISSION_NAME).")" >&2 return 1 diff --git a/missions/finding_files_maze/04_find_2/init.sh b/missions/finding_files_maze/04_find_2/init.sh index 7118721e..fbd72454 100644 --- a/missions/finding_files_maze/04_find_2/init.sh +++ b/missions/finding_files_maze/04_find_2/init.sh @@ -6,7 +6,7 @@ mkdir -p "$GSH_CHEST" _mission_init() ( if ! command -v generate_maze.sh >/dev/null then - DUMMY_MISSION=$(realpath "$MISSION_DIR/../00_shared") + DUMMY_MISSION=$(readlink-f "$MISSION_DIR/../00_shared") DUMMY_MISSION=${DUMMY_MISSION#$GSH_MISSIONS/} echo "$(eval_gettext "Dummy mission '\$DUMMY_MISSION' is required for mission \$MISSION_NB (\$MISSION_NAME).")" >&2 return 1 diff --git a/missions/finding_files_maze/05_find_xargs_grep/init.sh b/missions/finding_files_maze/05_find_xargs_grep/init.sh index f3350180..040ba977 100644 --- a/missions/finding_files_maze/05_find_xargs_grep/init.sh +++ b/missions/finding_files_maze/05_find_xargs_grep/init.sh @@ -6,7 +6,7 @@ mkdir -p "$GSH_CHEST" _mission_init() ( if ! command -v generate_maze.sh >/dev/null then - DUMMY_MISSION=$(realpath "$MISSION_DIR/../00_shared") + DUMMY_MISSION=$(readlink-f "$MISSION_DIR/../00_shared") DUMMY_MISSION=${DUMMY_MISSION#$GSH_MISSIONS/} echo "$(eval_gettext "Dummy mission '\$DUMMY_MISSION' is required for mission \$MISSION_NB (\$MISSION_NAME).")" >&2 return 1 diff --git a/missions/intermediate/02_alias_journal/check.sh b/missions/intermediate/02_alias_journal/check.sh index 8f52e6ac..b0d905aa 100644 --- a/missions/intermediate/02_alias_journal/check.sh +++ b/missions/intermediate/02_alias_journal/check.sh @@ -22,8 +22,8 @@ _mission_check() { # alias journal="nano journal.txt" # used from the Chest local target_path - target_path="$(cd / ; eval "${cmd/$EDITOR/realpath}" 2>/dev/null)" - if [ "$target_path" = "$(realpath "$GSH_CHEST/$(gettext "journal").txt" 2>/dev/null)" ] + target_path="$(cd / ; eval "${cmd/$EDITOR/readlink-f}" 2>/dev/null)" + if [ "$target_path" = "$(readlink-f "$GSH_CHEST/$(gettext "journal").txt" 2>/dev/null)" ] then return 0 else diff --git a/missions/intermediate/03_tab_spider_lair/check.sh b/missions/intermediate/03_tab_spider_lair/check.sh index aca3d9eb..edda615a 100644 --- a/missions/intermediate/03_tab_spider_lair/check.sh +++ b/missions/intermediate/03_tab_spider_lair/check.sh @@ -7,7 +7,7 @@ _mission_check() ( lair="$(find "$(eval_gettext '$GSH_HOME/Castle/Cellar')" -type d -name ".$(gettext "Lair_of_the_spider_queen")*")" - if [ "$(realpath "$(pwd)")" != "$(realpath "$lair")" ] + if [ "$(readlink-f "$(pwd)")" != "$(readlink-f "$lair")" ] then echo "$(gettext "You are not in the queen spider lair!")" return 1 diff --git a/missions/intermediate/04_bg_xeyes/auto.sh b/missions/intermediate/04_bg_xeyes/auto.sh index 42582b43..9047da7c 100644 --- a/missions/intermediate/04_bg_xeyes/auto.sh +++ b/missions/intermediate/04_bg_xeyes/auto.sh @@ -1,6 +1,6 @@ #!/bin/sh -. history_start.sh +. alt_history_start.sh add_cmd "xeyes" add_cmd "xeyes &" @@ -8,4 +8,4 @@ xeyes & add_cmd gsh check gsh check -. history_clean.sh +. alt_history_stop.sh diff --git a/missions/intermediate/04_bg_xeyes/check.sh b/missions/intermediate/04_bg_xeyes/check.sh index 79a31969..aaaa4d55 100644 --- a/missions/intermediate/04_bg_xeyes/check.sh +++ b/missions/intermediate/04_bg_xeyes/check.sh @@ -3,7 +3,7 @@ # fc in specified in POSIX, but debian's sh doesn't implement it! _mission_check() { - if ! (. previous_commands.sh | head -n 4 | grep -qx "[[:blank:]]*xeyes[[:blank:]]*") + if ! (. fc-lnr.sh | head -n 4 | grep -qx "[[:blank:]]*xeyes[[:blank:]]*") then echo "$(gettext "Have you run the 'xeyes' command directly?")" ps -e | awk '/xeyes/ {print $1}' | xargs kill -9 2> /dev/null diff --git a/missions/intermediate/04_bg_xeyes/test.sh b/missions/intermediate/04_bg_xeyes/test.sh index fbd87640..db8a0b57 100644 --- a/missions/intermediate/04_bg_xeyes/test.sh +++ b/missions/intermediate/04_bg_xeyes/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -. history_start.sh +. alt_history_start.sh add_cmd "xeyes" add_cmd "xeyes &" @@ -29,5 +29,5 @@ gsh assert check true ps -e | awk '/xeyes/ {print $1}' | xargs kill -9 2> /dev/null -. history_clean.sh +. alt_history_stop.sh diff --git a/missions/permissions/01_chmod_x_dir_king_quarter/check.sh b/missions/permissions/01_chmod_x_dir_king_quarter/check.sh index 5d097549..8eb68651 100644 --- a/missions/permissions/01_chmod_x_dir_king_quarter/check.sh +++ b/missions/permissions/01_chmod_x_dir_king_quarter/check.sh @@ -2,7 +2,7 @@ dir=$(eval_gettext '$GSH_HOME/Castle/Main_building/Throne_room/Kings_quarter') -if [ "$(realpath "$(pwd)" 2>/dev/null)" = "$(realpath "$dir" 2>/dev/null)" ] +if [ "$(readlink-f "$(pwd)" 2>/dev/null)" = "$(readlink-f "$dir" 2>/dev/null)" ] then unset dir true diff --git a/missions/permissions/01_chmod_x_dir_king_quarter/clean.sh b/missions/permissions/01_chmod_x_dir_king_quarter/clean.sh index 781e910c..41b7233d 100644 --- a/missions/permissions/01_chmod_x_dir_king_quarter/clean.sh +++ b/missions/permissions/01_chmod_x_dir_king_quarter/clean.sh @@ -7,8 +7,8 @@ case "$GSH_LAST_ACTION" in : ;; *) - _PWD="$(realpath $(pwd) 2>/dev/null)" - if [ -n "$_PWD" ] && [ "$_PWD" = "$(realpath "$king_quarter" 2>/dev/null)" ] + _PWD="$(readlink-f $(pwd) 2>/dev/null)" + if [ -n "$_PWD" ] && [ "$_PWD" = "$(readlink-f "$king_quarter" 2>/dev/null)" ] then cd .. fi diff --git a/missions/permissions/01_chmod_x_dir_king_quarter/init.sh b/missions/permissions/01_chmod_x_dir_king_quarter/init.sh index 7b190d4c..f06a0c8d 100644 --- a/missions/permissions/01_chmod_x_dir_king_quarter/init.sh +++ b/missions/permissions/01_chmod_x_dir_king_quarter/init.sh @@ -7,7 +7,7 @@ _mission_init() ( return 1 fi - [ "$(realpath "$(pwd)")" = "$(realpath "$dir")" ] && cd .. + [ "$(readlink-f "$(pwd)")" = "$(readlink-f "$dir")" ] && cd .. dir=$(eval_gettext '$GSH_HOME/Castle/Main_building/Throne_room/Kings_quarter') chmod -x "$dir" diff --git a/missions/permissions/03_chmod_rw_file_dir_throne_room/clean.sh b/missions/permissions/03_chmod_rw_file_dir_throne_room/clean.sh index 9063a26c..68aa47fe 100644 --- a/missions/permissions/03_chmod_rw_file_dir_throne_room/clean.sh +++ b/missions/permissions/03_chmod_rw_file_dir_throne_room/clean.sh @@ -7,8 +7,8 @@ case "$GSH_LAST_ACTION" in : ;; *) - _PWD="$(realpath $(pwd) 2>/dev/null)" - if [ -n "$_PWD" ] && [ "$_PWD" = "$(realpath "$safe" 2>/dev/null)" ] + _PWD="$(readlink-f $(pwd) 2>/dev/null)" + if [ -n "$_PWD" ] && [ "$_PWD" = "$(readlink-f "$safe" 2>/dev/null)" ] then cd "$(eval_gettext '$GSH_HOME/Castle/Main_building/Throne_room')" fi diff --git a/missions/pipe_intro_book_of_potions/01_head/auto.sh b/missions/pipe_intro_book_of_potions/01_head/auto.sh index 95749f4d..96363942 100644 --- a/missions/pipe_intro_book_of_potions/01_head/auto.sh +++ b/missions/pipe_intro_book_of_potions/01_head/auto.sh @@ -1,6 +1,6 @@ #!/bin/sh -. history_start.sh +. alt_history_start.sh cd "$(eval_gettext '$GSH_HOME/Mountain/Cave')" @@ -10,4 +10,4 @@ add_cmd head -n 6 "$(gettext "Book_of_potions")/$(gettext "page")_07" add_cmd gsh check gsh check -. history_clean.sh +. alt_history_stop.sh diff --git a/missions/pipe_intro_book_of_potions/01_head/check.sh b/missions/pipe_intro_book_of_potions/01_head/check.sh index af33f0db..aefb2cc3 100644 --- a/missions/pipe_intro_book_of_potions/01_head/check.sh +++ b/missions/pipe_intro_book_of_potions/01_head/check.sh @@ -3,10 +3,10 @@ _mission_check() ( cave="$(eval_gettext '$GSH_HOME/Mountain/Cave')" - pc=$(. previous_commands.sh | head -n1) + pc=$(. fc-lnr.sh | head -n1) - goal=$(realpath "$cave") - current=$(realpath "$PWD") + goal=$(readlink-f "$cave") + current=$(readlink-f "$PWD") if ! diff -q "$cave/$(gettext 'Book_of_potions')" "$GSH_TMP/book_of_potions" >/dev/null then diff --git a/missions/pipe_intro_book_of_potions/01_head/test.sh b/missions/pipe_intro_book_of_potions/01_head/test.sh index c07604f6..99bc6fb3 100644 --- a/missions/pipe_intro_book_of_potions/01_head/test.sh +++ b/missions/pipe_intro_book_of_potions/01_head/test.sh @@ -1,6 +1,6 @@ #!/bin/sh -. history_start.sh +. alt_history_start.sh cd "$(eval_gettext '$GSH_HOME/Mountain/Cave')" @@ -22,4 +22,4 @@ add_cmd "head -n 6 $(gettext "Book_of_potions")/$(gettext "page")_07" add_cmd gsh check gsh assert check false -. history_clean.sh +. alt_history_stop.sh diff --git a/missions/pipe_intro_book_of_potions/02_tail/auto.sh b/missions/pipe_intro_book_of_potions/02_tail/auto.sh index 85945dc3..a8da8f95 100644 --- a/missions/pipe_intro_book_of_potions/02_tail/auto.sh +++ b/missions/pipe_intro_book_of_potions/02_tail/auto.sh @@ -1,6 +1,6 @@ #!/bin/sh -. history_start.sh +. alt_history_start.sh cd "$(eval_gettext '$GSH_HOME/Mountain/Cave')" @@ -10,4 +10,4 @@ add_cmd tail -n 9 "$(gettext "Book_of_potions")/$(gettext "page")_12" add_cmd gsh check gsh check -. history_clean.sh +. alt_history_stop.sh diff --git a/missions/pipe_intro_book_of_potions/02_tail/check.sh b/missions/pipe_intro_book_of_potions/02_tail/check.sh index f715b5a4..c589f421 100644 --- a/missions/pipe_intro_book_of_potions/02_tail/check.sh +++ b/missions/pipe_intro_book_of_potions/02_tail/check.sh @@ -3,10 +3,10 @@ _mission_check() ( cave="$(eval_gettext '$GSH_HOME/Mountain/Cave')" - pc=$(. previous_commands.sh | head -n1) + pc=$(. fc-lnr.sh | head -n1) - goal=$(realpath "$cave") - current=$(realpath "$PWD") + goal=$(readlink-f "$cave") + current=$(readlink-f "$PWD") if ! diff -q "$cave/$(gettext 'Book_of_potions')" "$GSH_TMP/book_of_potions" > /dev/null then diff --git a/missions/pipe_intro_book_of_potions/02_tail/test.sh b/missions/pipe_intro_book_of_potions/02_tail/test.sh index b453aea2..60bcb626 100644 --- a/missions/pipe_intro_book_of_potions/02_tail/test.sh +++ b/missions/pipe_intro_book_of_potions/02_tail/test.sh @@ -1,6 +1,6 @@ #!/bin/sh -. history_start.sh +. alt_history_start.sh cd "$(eval_gettext '$GSH_HOME/Mountain/Cave')" @@ -26,4 +26,4 @@ add_cmd "tail -n 9 $(gettext "Book_of_potions")/$(gettext "page")_12" add_cmd gsh check gsh assert check false -. history_clean.sh +. alt_history_stop.sh diff --git a/missions/pipe_intro_book_of_potions/03_cat/auto.sh b/missions/pipe_intro_book_of_potions/03_cat/auto.sh index 709b0332..46d4b38d 100644 --- a/missions/pipe_intro_book_of_potions/03_cat/auto.sh +++ b/missions/pipe_intro_book_of_potions/03_cat/auto.sh @@ -1,6 +1,6 @@ #!/bin/sh -. history_start.sh +. alt_history_start.sh cd "$(eval_gettext '$GSH_HOME/Mountain/Cave')" @@ -10,4 +10,4 @@ add_cmd cat "$(gettext "Book_of_potions")/$(gettext "page")_01" "$(gettext "Book add_cmd gsh check gsh check -. history_clean.sh +. alt_history_stop.sh diff --git a/missions/pipe_intro_book_of_potions/03_cat/check.sh b/missions/pipe_intro_book_of_potions/03_cat/check.sh index 68abfd11..160785b0 100644 --- a/missions/pipe_intro_book_of_potions/03_cat/check.sh +++ b/missions/pipe_intro_book_of_potions/03_cat/check.sh @@ -3,10 +3,10 @@ _mission_check() ( cave="$(eval_gettext '$GSH_HOME/Mountain/Cave')" - pc=$(. previous_commands.sh | head -n1) + pc=$(. fc-lnr.sh | head -n1) - goal=$(realpath "$cave") - current=$(realpath "$PWD") + goal=$(readlink-f "$cave") + current=$(readlink-f "$PWD") if ! diff -q "$cave/$(gettext 'Book_of_potions')" "$GSH_TMP/book_of_potions" > /dev/null then diff --git a/missions/pipe_intro_book_of_potions/03_cat/test.sh b/missions/pipe_intro_book_of_potions/03_cat/test.sh index 439f04c3..ed0bf9c8 100644 --- a/missions/pipe_intro_book_of_potions/03_cat/test.sh +++ b/missions/pipe_intro_book_of_potions/03_cat/test.sh @@ -1,6 +1,6 @@ #!/bin/sh -. history_start.sh +. alt_history_start.sh cd "$(eval_gettext '$GSH_HOME/Mountain/Cave')" @@ -30,4 +30,4 @@ add_cmd "cat \"$(gettext "Book_of_potions")/$(gettext "page")_0\"[12]" add_cmd gsh check gsh assert check false -. history_clean.sh +. alt_history_stop.sh diff --git a/missions/pipe_intro_book_of_potions/04_pipe/auto.sh b/missions/pipe_intro_book_of_potions/04_pipe/auto.sh index afb03c5a..7f0f58dd 100644 --- a/missions/pipe_intro_book_of_potions/04_pipe/auto.sh +++ b/missions/pipe_intro_book_of_potions/04_pipe/auto.sh @@ -1,6 +1,6 @@ #!/bin/sh -. history_start.sh +. alt_history_start.sh cd "$(eval_gettext '$GSH_HOME/Mountain/Cave')" @@ -10,4 +10,4 @@ add_cmd "cat \"$(gettext "Book_of_potions")/$(gettext "page")_0\"[34] | tail -n add_cmd gsh check gsh check -. history_clean.sh +. alt_history_stop.sh diff --git a/missions/pipe_intro_book_of_potions/04_pipe/check.sh b/missions/pipe_intro_book_of_potions/04_pipe/check.sh index d50c84ff..17bb1d2b 100644 --- a/missions/pipe_intro_book_of_potions/04_pipe/check.sh +++ b/missions/pipe_intro_book_of_potions/04_pipe/check.sh @@ -3,10 +3,10 @@ _mission_check() ( cave="$(eval_gettext '$GSH_HOME/Mountain/Cave')" - pc=$(. previous_commands.sh | head -n1) + pc=$(. fc-lnr.sh | head -n1) - goal=$(realpath "$cave") - current=$(realpath "$PWD") + goal=$(readlink-f "$cave") + current=$(readlink-f "$PWD") if ! diff -q "$cave/$(gettext 'Book_of_potions')" "$GSH_TMP/book_of_potions" > /dev/null then diff --git a/missions/pipe_intro_book_of_potions/04_pipe/test.sh b/missions/pipe_intro_book_of_potions/04_pipe/test.sh index ac968517..5ac24ef2 100644 --- a/missions/pipe_intro_book_of_potions/04_pipe/test.sh +++ b/missions/pipe_intro_book_of_potions/04_pipe/test.sh @@ -1,6 +1,6 @@ #!/bin/sh -. history_start.sh +. alt_history_start.sh cd "$(eval_gettext '$GSH_HOME/Mountain/Cave')" @@ -22,4 +22,4 @@ add_cmd "cat \"$(gettext "Book_of_potions")/$(gettext "page")_0\"[34] | tail -n add_cmd gsh check gsh assert check false -. history_clean.sh +. alt_history_stop.sh diff --git a/missions/pipe_intro_book_of_potions/05_pipe_head_tail/auto.sh b/missions/pipe_intro_book_of_potions/05_pipe_head_tail/auto.sh index 55be5468..e8fed387 100644 --- a/missions/pipe_intro_book_of_potions/05_pipe_head_tail/auto.sh +++ b/missions/pipe_intro_book_of_potions/05_pipe_head_tail/auto.sh @@ -1,6 +1,6 @@ #!/bin/sh -. history_start.sh +. alt_history_start.sh cd "$(eval_gettext '$GSH_HOME/Mountain/Cave')" @@ -10,4 +10,4 @@ add_cmd "head -n 6 \"$(gettext "Book_of_potions")/$(gettext "page")_13\" | tail add_cmd gsh check gsh check -. history_clean.sh +. alt_history_stop.sh diff --git a/missions/pipe_intro_book_of_potions/05_pipe_head_tail/check.sh b/missions/pipe_intro_book_of_potions/05_pipe_head_tail/check.sh index 7569da32..511cb950 100644 --- a/missions/pipe_intro_book_of_potions/05_pipe_head_tail/check.sh +++ b/missions/pipe_intro_book_of_potions/05_pipe_head_tail/check.sh @@ -3,10 +3,10 @@ _mission_check() ( cave="$(eval_gettext '$GSH_HOME/Mountain/Cave')" - pc=$(. previous_commands.sh | head -n1) + pc=$(. fc-lnr.sh | head -n1) - goal=$(realpath "$cave") - current=$(realpath "$PWD") + goal=$(readlink-f "$cave") + current=$(readlink-f "$PWD") if ! diff -q "$cave/$(gettext 'Book_of_potions')" "$GSH_TMP/book_of_potions" > /dev/null then diff --git a/missions/pipe_intro_book_of_potions/05_pipe_head_tail/test.sh b/missions/pipe_intro_book_of_potions/05_pipe_head_tail/test.sh index f78dc4b5..fa9cf74a 100644 --- a/missions/pipe_intro_book_of_potions/05_pipe_head_tail/test.sh +++ b/missions/pipe_intro_book_of_potions/05_pipe_head_tail/test.sh @@ -1,6 +1,6 @@ #!/bin/sh -. history_start.sh +. alt_history_start.sh cd "$(eval_gettext '$GSH_HOME/Mountain/Cave')" @@ -34,4 +34,4 @@ add_cmd "head -n 6 \"$(gettext "Book_of_potions")/$(gettext 'page')_13\" | tail add_cmd gsh check gsh assert check false -. history_clean.sh +. alt_history_stop.sh diff --git a/missions/stdin_stdout_stderr/04_stderr_dev-null_grimoires/auto.sh b/missions/stdin_stdout_stderr/04_stderr_dev-null_grimoires/auto.sh index de634ea8..ea06eb27 100644 --- a/missions/stdin_stdout_stderr/04_stderr_dev-null_grimoires/auto.sh +++ b/missions/stdin_stdout_stderr/04_stderr_dev-null_grimoires/auto.sh @@ -1,6 +1,6 @@ #!/bin/sh -. history_start.sh +. alt_history_start.sh cd "$(eval_gettext '$GSH_HOME/Castle/Main_building/Library/Merlin_s_office')" @@ -9,4 +9,4 @@ grep -il "gsh" "$(gettext "grimoire")"_* 2> /dev/null add_cmd gsh check gsh check -. history_clean.sh +. alt_history_stop.sh diff --git a/missions/stdin_stdout_stderr/04_stderr_dev-null_grimoires/check.sh b/missions/stdin_stdout_stderr/04_stderr_dev-null_grimoires/check.sh index 6e83dc9a..d6742b37 100644 --- a/missions/stdin_stdout_stderr/04_stderr_dev-null_grimoires/check.sh +++ b/missions/stdin_stdout_stderr/04_stderr_dev-null_grimoires/check.sh @@ -1,7 +1,7 @@ #!/bin/sh _mission_check() ( - pc=$(. previous_commands.sh | head -n 1) + pc=$(. fc-lnr.sh | head -n 1) echo "$pc" | grep -q 'gsh\s\s*check' && return 1 @@ -12,6 +12,7 @@ _mission_check() ( fi temp_file=$(mktemp) + echo "pc=$pc" eval "$pc" | sort >"$temp_file" if cmp -s "$GSH_TMP/list_grimoires_GSH" "$temp_file" then diff --git a/bin/RANDOM b/scripts/RANDOM similarity index 100% rename from bin/RANDOM rename to scripts/RANDOM diff --git a/bin/_gsh_HELP b/scripts/_gsh_HELP similarity index 100% rename from bin/_gsh_HELP rename to scripts/_gsh_HELP diff --git a/bin/_gsh_goal b/scripts/_gsh_goal similarity index 100% rename from bin/_gsh_goal rename to scripts/_gsh_goal diff --git a/bin/_gsh_help b/scripts/_gsh_help similarity index 100% rename from bin/_gsh_help rename to scripts/_gsh_help diff --git a/bin/_gsh_index b/scripts/_gsh_index similarity index 100% rename from bin/_gsh_index rename to scripts/_gsh_index diff --git a/bin/_gsh_log b/scripts/_gsh_log similarity index 80% rename from bin/_gsh_log rename to scripts/_gsh_log index 2b3f371c..6bdfedbf 100755 --- a/bin/_gsh_log +++ b/scripts/_gsh_log @@ -3,7 +3,7 @@ GSH_ROOT=$(cd "$(dirname "$0")/.." && pwd -P) # we need access to checksum and missiondir -PATH=$PATH:$GSH_ROOT/bin +PATH=$PATH:$GSH_ROOT/scripts if [ "$1" = "-v" ] then @@ -14,5 +14,5 @@ fi awk -v UID="$(cat "$GSH_ROOT/.config/uid")" \ -v VERBOSE="$VERBOSE" \ -v MISSION_NB="$1" \ - -f "$GSH_ROOT/bin/_gsh_log.awk" \ + -f "$GSH_ROOT/scripts/_gsh_log.awk" \ "$GSH_ROOT/.config/missions.log" diff --git a/bin/_gsh_log.awk b/scripts/_gsh_log.awk similarity index 100% rename from bin/_gsh_log.awk rename to scripts/_gsh_log.awk diff --git a/bin/_gsh_pcm b/scripts/_gsh_pcm similarity index 100% rename from bin/_gsh_pcm rename to scripts/_gsh_pcm diff --git a/bin/_gsh_protect b/scripts/_gsh_protect similarity index 100% rename from bin/_gsh_protect rename to scripts/_gsh_protect diff --git a/bin/_gsh_stat b/scripts/_gsh_stat similarity index 72% rename from bin/_gsh_stat rename to scripts/_gsh_stat index ff3d8b3e..d28d9fd9 100755 --- a/bin/_gsh_stat +++ b/scripts/_gsh_stat @@ -3,8 +3,8 @@ GSH_ROOT=$(cd "$(dirname "$0")/.." && pwd -P) # we need access to checksum and missiondir -PATH=$PATH:$GSH_ROOT/bin +PATH=$PATH:$GSH_ROOT/scripts awk -v UID="$(cat "$GSH_ROOT/.config/uid")" \ - -f "$GSH_ROOT/bin/_gsh_stat.awk" \ + -f "$GSH_ROOT/scripts/_gsh_stat.awk" \ "$GSH_ROOT/.config/missions.log" diff --git a/bin/_gsh_stat.awk b/scripts/_gsh_stat.awk similarity index 100% rename from bin/_gsh_stat.awk rename to scripts/_gsh_stat.awk diff --git a/bin/_gsh_systemconfig b/scripts/_gsh_systemconfig similarity index 100% rename from bin/_gsh_systemconfig rename to scripts/_gsh_systemconfig diff --git a/bin/_gsh_unprotect b/scripts/_gsh_unprotect similarity index 100% rename from bin/_gsh_unprotect rename to scripts/_gsh_unprotect diff --git a/bin/_gsh_welcome b/scripts/_gsh_welcome similarity index 100% rename from bin/_gsh_welcome rename to scripts/_gsh_welcome diff --git a/bin/admin_mode b/scripts/admin_mode similarity index 100% rename from bin/admin_mode rename to scripts/admin_mode diff --git a/bin/history_start.sh b/scripts/alt_history_start.sh similarity index 79% rename from bin/history_start.sh rename to scripts/alt_history_start.sh index a3b9ba0e..254e2db0 100644 --- a/bin/history_start.sh +++ b/scripts/alt_history_start.sh @@ -1,12 +1,12 @@ # -# this script, together with its companion history_clean.sh is used to record +# this script, together with its companion alt_history_stop.sh is used to record # manually commands in a temporary history # This is used to test missions that require inputing specific commands. # It works with bash and zsh. # -# To use, **source** history_start.sh. This will start a separate history. +# To use, **source** alt_history_start.sh. This will start a separate history. # Use the function add_cmd to add commands to the history. -# When you're done, **source** history_clean.sh to go back to the original +# When you're done, **source** alt_history_stop.sh to go back to the original # history. # # NOTE, on old versions of bash (e.g. in macos), fc removes the last command, even diff --git a/bin/history_clean.sh b/scripts/alt_history_stop.sh similarity index 77% rename from bin/history_clean.sh rename to scripts/alt_history_stop.sh index 2a37db40..60d2bcd3 100644 --- a/bin/history_clean.sh +++ b/scripts/alt_history_stop.sh @@ -1,12 +1,12 @@ # -# this script, together with its companion history_start.sh is used to record +# this script, together with its companion alt_history_start.sh is used to record # manually commands in a temporary history # This is used to test missions that require inputing specific commands. # It works with bash and zsh. # -# To use, **source** history_start.sh. This will start a separate history. +# To use, **source** alt_history_start.sh. This will start a separate history. # Use the function add_cmd to add commands to the history. -# When you're done, **source** history_clean.sh to go back to the original +# When you're done, **source** alt_history_stop.sh to go back to the original # history. # # NOTE, on old versions of bash (e.g. in macos), fc removes the last command, even diff --git a/bin/box.awk b/scripts/box.awk similarity index 100% rename from bin/box.awk rename to scripts/box.awk diff --git a/bin/box.sh b/scripts/box.sh similarity index 100% rename from bin/box.sh rename to scripts/box.sh diff --git a/bin/check_file b/scripts/check_file similarity index 100% rename from bin/check_file rename to scripts/check_file diff --git a/bin/checksum b/scripts/checksum similarity index 100% rename from bin/checksum rename to scripts/checksum diff --git a/bin/color_echo b/scripts/color_echo similarity index 100% rename from bin/color_echo rename to scripts/color_echo diff --git a/bin/copy_bin b/scripts/copy_bin similarity index 100% rename from bin/copy_bin rename to scripts/copy_bin diff --git a/bin/create_boxes_data.awk b/scripts/create_boxes_data.awk similarity index 100% rename from bin/create_boxes_data.awk rename to scripts/create_boxes_data.awk diff --git a/bin/previous_commands.sh b/scripts/fc-lnr.sh similarity index 78% rename from bin/previous_commands.sh rename to scripts/fc-lnr.sh index 543bac1e..873e4d83 100644 --- a/bin/previous_commands.sh +++ b/scripts/fc-lnr.sh @@ -1,6 +1,11 @@ # shows the 10 previous commands using fc -nlr # this must be SOURCED # +# if the script receives a $1 argument, it is used instead of "10". +# (You can either rely on bash / zsh ability to pass arguments while sourcing, +# or set it explicitly with +# set NB ; . fc-lnr.sh +# # This script is necessary because of some strange behaviour with bash: # when sourcing a script from inside a function, the function call is added # during the "source", removed after the "source", and added again after the @@ -29,7 +34,9 @@ # As an ugly fix, I manually remove that additional command! fc -nl | # get the history - tail -n 11 | # keep at most the last 11 commands + tail -n ${1:-10} | # keep at most the last 10 commands awk '{L[l++]=$0} END {while (l>0) print L[--l]}' | # reverse the lines, to get last command on first line awk 'NR==1 && $0 ~ "gsh *check" {next}; {print}' | # remove the first line, if it matches "gsh *check" - sed -e "s/^[[:blank:]]*//" -e "s/[[blank:]]*$//" # remove leading /trailing spaces + sed -e "s/^[[:blank:]]*//" -e "s/[[:blank:]]*$//" # remove leading /trailing spaces + +set -- diff --git a/bin/generate_rcfile b/scripts/generate_rcfile similarity index 100% rename from bin/generate_rcfile rename to scripts/generate_rcfile diff --git a/bin/gsh_gettext.sh b/scripts/gsh_gettext.sh similarity index 100% rename from bin/gsh_gettext.sh rename to scripts/gsh_gettext.sh diff --git a/bin/mainshell.sh b/scripts/mainshell.sh similarity index 100% rename from bin/mainshell.sh rename to scripts/mainshell.sh diff --git a/bin/make_index b/scripts/make_index similarity index 96% rename from bin/make_index rename to scripts/make_index index f9138b7b..66b7c851 100755 --- a/bin/make_index +++ b/scripts/make_index @@ -61,7 +61,7 @@ parse_mission() ( # use a subshell to have "local" variables (the functions are mutually # recursive) parse_index() ( - index_file=$(realpath "$1") + index_file=$(readlink-f "$1") case "$index_file" in "$GSH_MISSIONS"* ) @@ -99,7 +99,7 @@ parse_index() ( MISSION_DIR=$dir/$MISSION_DIR if [ -e "$MISSION_DIR" ] then - parse_mission "$DUMMY$(realpath "$MISSION_DIR")" || exit 1 + parse_mission "$DUMMY$(readlink-f "$MISSION_DIR")" || exit 1 else echo "Error: make_index, invalid argument (parse_index): '${MISSION_DIR#$GSH_MISSIONS/}'" >&2 exit 1 @@ -120,7 +120,7 @@ make_index() { while [ "$#" -gt 0 ] do - MISSION_DIR=$(realpath "$1") + MISSION_DIR=$(readlink-f "$1") if [ -e "$MISSION_DIR" ] then parse_mission "$MISSION_DIR" || exit 1 diff --git a/bin/missiondir b/scripts/missiondir similarity index 95% rename from bin/missiondir rename to scripts/missiondir index d991df82..bad4eacc 100755 --- a/bin/missiondir +++ b/scripts/missiondir @@ -18,7 +18,7 @@ then echo "Error: missiondir, mission '$n' not found." >&2 exit 1 fi -dir=$(realpath "$dir") +dir=$(readlink-f "$dir") if [ -z "$RELATIVE" ] then diff --git a/bin/missionname b/scripts/missionname similarity index 96% rename from bin/missionname rename to scripts/missionname index 4f32797b..8249603c 100755 --- a/bin/missionname +++ b/scripts/missionname @@ -4,7 +4,7 @@ GSH_ROOT=$(cd "$(dirname "$0")/.." && pwd -P) GSH_MISSIONS=$GSH_ROOT/missions missionname() { - path=$(realpath "$1") + path=$(readlink-f "$1") if ! [ -e "$path" ] then diff --git a/bin/pager b/scripts/pager similarity index 100% rename from bin/pager rename to scripts/pager diff --git a/bin/parchment b/scripts/parchment similarity index 100% rename from bin/parchment rename to scripts/parchment diff --git a/bin/save_environment.sh b/scripts/print_current_environment.sh similarity index 100% rename from bin/save_environment.sh rename to scripts/print_current_environment.sh diff --git a/bin/progress_bar b/scripts/progress_bar similarity index 100% rename from bin/progress_bar rename to scripts/progress_bar diff --git a/bin/progress_bar.sh b/scripts/progress_bar.sh similarity index 99% rename from bin/progress_bar.sh rename to scripts/progress_bar.sh index 138155d2..f7c6e92b 100644 --- a/bin/progress_bar.sh +++ b/scripts/progress_bar.sh @@ -18,6 +18,7 @@ or . progress_bar.sh [-b DESIGN] COMMAND if your shell is stricly POSIX EOS + set -- false else design=RANDOM diff --git a/bin/random_string b/scripts/random_string similarity index 100% rename from bin/random_string rename to scripts/random_string diff --git a/bin/realpath b/scripts/readlink-f similarity index 100% rename from bin/realpath rename to scripts/readlink-f diff --git a/bin/reflow.awk b/scripts/reflow.awk similarity index 100% rename from bin/reflow.awk rename to scripts/reflow.awk diff --git a/bin/sed-i b/scripts/sed-i similarity index 100% rename from bin/sed-i rename to scripts/sed-i diff --git a/bin/seq b/scripts/seq similarity index 100% rename from bin/seq rename to scripts/seq diff --git a/bin/sign_file b/scripts/sign_file similarity index 100% rename from bin/sign_file rename to scripts/sign_file diff --git a/bin/textdomainname b/scripts/textdomainname similarity index 51% rename from bin/textdomainname rename to scripts/textdomainname index df91e6c3..823e620b 100755 --- a/bin/textdomainname +++ b/scripts/textdomainname @@ -1,4 +1,4 @@ #!/bin/sh GSH_ROOT=$(cd "$(dirname "$0")/.." && pwd -P) -"$GSH_ROOT/bin/missionname" "$1" | sed 's|/|,|g' +"$GSH_ROOT/scripts/missionname" "$1" | sed 's|/|,|g' diff --git a/bin/treasure_message b/scripts/treasure_message similarity index 93% rename from bin/treasure_message rename to scripts/treasure_message index 352b2c6e..ff264d4a 100755 --- a/bin/treasure_message +++ b/scripts/treasure_message @@ -23,7 +23,7 @@ display_message() { # [ "$reflow_width" -gt 100 ] && reflow_width=100 echo - "$GSH_ROOT/bin/reflow.awk" -v width=$reflow_width "$treasure_msg_file" | + "$GSH_ROOT/scripts/reflow.awk" -v width=$reflow_width "$treasure_msg_file" | paste "$GSH_LIB/ascii-art/treasure-chest.txt" - | awk -v width=$WIDTH -v seed_file="$GSH_CONFIG/PRNG_seed" ' BEGIN{ diff --git a/start.sh b/start.sh index e88789a9..ef544bbe 100755 --- a/start.sh +++ b/start.sh @@ -15,11 +15,10 @@ export GSH_ROOT="$(dirname "$0")" +# shellcheck source=scripts/gsh_gettext.sh +. "$GSH_ROOT/scripts/gsh_gettext.sh" # shellcheck source=lib/profile.sh . "$GSH_ROOT/lib/profile.sh" - -# shellcheck source=bin/gsh_gettext.sh -. "$GSH_ROOT/bin/gsh_gettext.sh" # shellcheck source=lib/mission_source.sh . "$GSH_ROOT/lib/mission_source.sh" diff --git a/tests/test-history.sh b/tests/test-history.sh index bd0cb6ad..ef515d11 100755 --- a/tests/test-history.sh +++ b/tests/test-history.sh @@ -16,12 +16,12 @@ test_history() { export HISTSIZE=10 export HISTFILESIZE=10 fc -ln - source ./bin/history_start.sh + source ./bin/alt_history_start.sh add_cmd A add_cmd B add_cmd C fc -ln - source ./bin/history_clean.sh + source ./bin/alt_history_stop.sh fc -ln ' ;; @@ -34,12 +34,12 @@ test_history() { export HISTSIZE=10 export SAVEHIST=10 fc -ln - source ./bin/history_start.sh + source ./bin/alt_history_start.sh add_cmd A add_cmd B add_cmd C fc -ln - source ./bin/history_clean.sh + source ./bin/alt_history_stop.sh fc -ln ' ;; diff --git a/utils/archive.sh b/utils/archive.sh index 20da85b4..ab3d3339 100755 --- a/utils/archive.sh +++ b/utils/archive.sh @@ -117,7 +117,7 @@ mkdir "$TMP_DIR/$NAME" # copy source files # NOTE: macOS' cp doesn't have '--archive', and '-a' is not POSIX. # use POSIX options to make sure it is portable -cp -RPp "$GSH_ROOT/start.sh" "$GSH_ROOT/bin" "$GSH_ROOT/utils" "$GSH_ROOT/lib" "$GSH_ROOT/i18n" "$TMP_DIR/$NAME" +cp -RPp "$GSH_ROOT/start.sh" "$GSH_ROOT/scripts" "$GSH_ROOT/utils" "$GSH_ROOT/lib" "$GSH_ROOT/i18n" "$TMP_DIR/$NAME" # copy missions mkdir "$TMP_DIR/$NAME/missions" @@ -257,7 +257,7 @@ echo "removing unnecessary files" [ "$KEEP_TEST" -ne 1 ] && find ./missions -name "test.sh" | xargs rm -f [ "$KEEP_AUTO" -ne 1 ] && find ./missions -name auto.sh | xargs rm -f - # rm -f "$GSH_ROOT/bin/boxes-data.awk" "$GSH_ROOT/utils/archive.sh" + # rm -f "$GSH_ROOT/scripts/boxes-data.awk" "$GSH_ROOT/utils/archive.sh" ) # change admin password