Skip to content

Commit

Permalink
renaming of files and dirs to be more consistent
Browse files Browse the repository at this point in the history
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
  • Loading branch information
phyver committed Jul 1, 2021
1 parent 057bae4 commit 03a71a4
Show file tree
Hide file tree
Showing 89 changed files with 123 additions and 115 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"*

Expand Down
18 changes: 9 additions & 9 deletions lib/bin_test.sh
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/gsh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/gshrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/mission_source.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/profile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

4 changes: 2 additions & 2 deletions missions/basic/01_cd_tower/check.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions missions/basic/02_cd.._cellar/check.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions missions/basic/03_cd_HOME_throne/auto.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

. history_start.sh
. alt_history_start.sh

cd "$(eval_gettext '$GSH_HOME/Castle/Main_building/Throne_room')"

Expand All @@ -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
6 changes: 3 additions & 3 deletions missions/basic/03_cd_HOME_throne/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions missions/basic/03_cd_HOME_throne/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

. history_start.sh
. alt_history_start.sh

# add dummy commands to avoid error messages
add_cmd dummy1
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion missions/finding_files_maze/01_ls_cd/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion missions/finding_files_maze/02_tree/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion missions/finding_files_maze/03_find_1/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion missions/finding_files_maze/04_find_2/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion missions/finding_files_maze/05_find_xargs_grep/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions missions/intermediate/02_alias_journal/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion missions/intermediate/03_tab_spider_lair/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions missions/intermediate/04_bg_xeyes/auto.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/sh

. history_start.sh
. alt_history_start.sh

add_cmd "xeyes"
add_cmd "xeyes &"
xeyes &
add_cmd gsh check
gsh check

. history_clean.sh
. alt_history_stop.sh
2 changes: 1 addition & 1 deletion missions/intermediate/04_bg_xeyes/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions missions/intermediate/04_bg_xeyes/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

. history_start.sh
. alt_history_start.sh

add_cmd "xeyes"
add_cmd "xeyes &"
Expand Down Expand Up @@ -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

2 changes: 1 addition & 1 deletion missions/permissions/01_chmod_x_dir_king_quarter/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions missions/permissions/01_chmod_x_dir_king_quarter/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion missions/permissions/01_chmod_x_dir_king_quarter/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions missions/pipe_intro_book_of_potions/01_head/auto.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

. history_start.sh
. alt_history_start.sh

cd "$(eval_gettext '$GSH_HOME/Mountain/Cave')"

Expand All @@ -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
6 changes: 3 additions & 3 deletions missions/pipe_intro_book_of_potions/01_head/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions missions/pipe_intro_book_of_potions/01_head/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

. history_start.sh
. alt_history_start.sh

cd "$(eval_gettext '$GSH_HOME/Mountain/Cave')"

Expand All @@ -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
4 changes: 2 additions & 2 deletions missions/pipe_intro_book_of_potions/02_tail/auto.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

. history_start.sh
. alt_history_start.sh

cd "$(eval_gettext '$GSH_HOME/Mountain/Cave')"

Expand All @@ -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
Loading

0 comments on commit 03a71a4

Please sign in to comment.