Skip to content

Commit

Permalink
return outside function
Browse files Browse the repository at this point in the history
should fix #48
  • Loading branch information
phyver committed Jun 11, 2021
1 parent 2f4ee13 commit 81852cc
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 52 deletions.
20 changes: 12 additions & 8 deletions bin/_gsh_pcm
Expand Up @@ -3,11 +3,15 @@
# pcm => "print current mission"
GSH_CONFIG=$(cd "$(dirname "$0")/../.config"; pwd -P)

PCM="$(awk '/^#/ {next} $2=="START" {m=$1} END {print (m)}' "$GSH_CONFIG/missions.log")"
if [ -z "$PCM" ]
then
echo "1"
return 1
else
echo "$PCM"
fi
pcm() {
PCM="$(awk '/^#/ {next} $2=="START" {m=$1} END {print (m)}' "$GSH_CONFIG/missions.log")"
if [ -z "$PCM" ]
then
echo "1"
return 1
else
echo "$PCM"
fi
}

pcm "$@"
11 changes: 7 additions & 4 deletions bin/_gsh_welcome
Expand Up @@ -2,7 +2,10 @@

. gettext.sh

# display welcome message
msg_file=$(eval_gettext '$GSH_ROOT/i18n/gameshell-welcome/en.txt')
[ -r "$msg_file" ] || return 1
parchment "$msg_file" | pager
welcome() {
# display welcome message
msg_file=$(eval_gettext '$GSH_ROOT/i18n/gameshell-welcome/en.txt')
[ -r "$msg_file" ] || return 1
parchment "$msg_file" | pager
}
welcome "$@"
12 changes: 6 additions & 6 deletions bin/copy_bin
@@ -1,14 +1,14 @@
#!/bin/sh

if [ -z "$MISSION_DIR" ]
then
echo "Error: copy_bin \$MISSION_DIR undefined." >&2
return 1
fi

# create a script to call a mission executable with appropriate context:
# correct TEXTDOMAIN (for translations) and MISSION_DIR (to use data files)
copy_bin() {
if [ -z "$MISSION_DIR" ]
then
echo "Error: copy_bin \$MISSION_DIR undefined." >&2
return 1
fi

if [ "$#" -ne 2 ]
then
echo "Error: copy_bin requires 2 arguments." >&2
Expand Down
71 changes: 37 additions & 34 deletions bin/missionname
Expand Up @@ -3,38 +3,41 @@
GSH_ROOT=$(cd "$(dirname "$0")/.." && pwd -P)
GSH_MISSIONS=$GSH_ROOT/missions

path=$(realpath "$1")

if ! [ -e "$path" ]
then
echo "Error missionname: path doesn't exist ('$1')." >&2
return 1
elif [ -f "$path" ]
then
cd "$(dirname "$path")"
else
cd "$path"
fi

while true
do
[ -f check.sh ] && break
[ -f static.sh ] && break
[ -f init.sh ] && break
[ $(pwd -P) = "/" ] && break
cd ..
done



case "$PWD" in
"$GSH_MISSIONS/"*)
path=$(pwd -P)
echo "${path#$GSH_MISSIONS/}"
;;
*)
echo "Error missionname: not a mission path ('$1')." >&2
return 1
;;
esac
missionname() {
path=$(realpath "$1")

if ! [ -e "$path" ]
then
echo "Error missionname: path doesn't exist ('$1')." >&2
return 1
elif [ -f "$path" ]
then
cd "$(dirname "$path")"
else
cd "$path"
fi

while true
do
[ -f check.sh ] && break
[ -f static.sh ] && break
[ -f init.sh ] && break
[ $(pwd -P) = "/" ] && break
cd ..
done



case "$PWD" in
"$GSH_MISSIONS/"*)
path=$(pwd -P)
echo "${path#$GSH_MISSIONS/}"
;;
*)
echo "Error missionname: not a mission path ('$1')." >&2
return 1
;;
esac
}

missionname "$@"

0 comments on commit 81852cc

Please sign in to comment.