diff options
author | KatolaZ <katolaz@freaknet.org> | 2019-01-24 10:40:35 +0000 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2019-01-24 10:40:35 +0000 |
commit | 3f4090d1ddb2f11fdf3f86da516a68a2ecee7d4b (patch) | |
tree | 4f26ed6b06db8ae1d7ee75365733b8284163e204 | |
parent | 22a92b1d449a67f86e599b67fc43235fb168e31c (diff) |
rearrange code to remove redundancies
-rwxr-xr-x | gophed | 53 |
1 files changed, 30 insertions, 23 deletions
@@ -36,10 +36,10 @@ fi if [ "$1" = "-h" ]; then usage; fi -if [ "$1" = "-i" ]; then - ln -s $0 g - ln -s $0 d - ln -s $0 v +if [ "$0" = "gophed" -a "$1" = "-i" ]; then + ln -sf $0 g + ln -sf $0 d + ln -sf $0 v exit 0 fi @@ -50,26 +50,33 @@ if [ "${script_name}" = "gophed" -o "${script_name}" = "v" ]; then TMPFILE=$(mktemp /tmp/gophed_$2_${sel}_$3.XXXXXXXXXXXXXXXXXXX) go "$1" "$2" "$3" > $TMPFILE cat $SHOW - | ed -p ${PROMPT} $TMPFILE + cleanup + exit 0 fi -if [ "${script_name}" = "g" ]; then - LINE=$(awk "{if (NR == $2) print \$0;}" $1) - RESOURCE=$(echo "$LINE" | cut -d ' ' -f 2) - HOST=$(echo "$LINE" | cut -d ' ' -f 3) - PORT=$(echo "$LINE" | awk -F ' ' '{ match($4,/[[:digit:]]+/); print substr($4,RSTART,RLENGTH) }') - SEL=$(echo $RESOURCE | sed -r 's:/:+:g') - TMPFILE=$(mktemp /tmp/gophed_${HOST}_${SEL}_${PORT}.XXXXXXXXXXXXXXXXXXX) - go "$RESOURCE" "$HOST" "$PORT" > $TMPFILE - cat $SHOW - | ed -p ${PROMPT} $TMPFILE -fi -if [ "${script_name}" = "d" ]; then - LINE=$(awk "{if (NR == $2) print \$0;}" $1) - RESOURCE=$(echo "$LINE" | cut -d ' ' -f 2) - HOST=$(echo "$LINE" | cut -d ' ' -f 3) - PORT=$(echo "$LINE" | awk -F ' ' '{ match($4,/[[:digit:]]+/); print substr($4,RSTART,RLENGTH) }') - DIR_RESOURCE=$(dirname $RESOURCE) - echo "Download $RESOURCE in ${HOST}${RESOURCE}" - mkdir -p "$HOST/$DIR_RESOURCE" - go "$RESOURCE" "$HOST" "$PORT" > "${HOST}${RESOURCE}" + +if [ ${script_name} = "g" -o ${script_name} = "d" ]; then + LINE=$(awk "{if (NR == $2) print \$0;}" $1) + RESOURCE=$(echo "$LINE" | cut -d ' ' -f 2) + HOST=$(echo "$LINE" | cut -d ' ' -f 3) + PORT=$(echo "$LINE" | awk -F ' ' '{ match($4,/[[:digit:]]+/); print substr($4,RSTART,RLENGTH) }') + + if [ "${script_name}" = "g" ]; then + SEL=$(echo $RESOURCE | sed -r 's:/:+:g') + TMPFILE=$(mktemp /tmp/gophed_${HOST}_${SEL}_${PORT}.XXXXXXXXXXXXXXXXXXX) + go "$RESOURCE" "$HOST" "$PORT" > $TMPFILE + cat $SHOW - | ed -p ${PROMPT} $TMPFILE + fi + if [ "${script_name}" = "d" ]; then + DIR_RESOURCE=$(dirname $RESOURCE) + echo "Download $RESOURCE in ${HOST}${RESOURCE}" + mkdir -p "$HOST/$DIR_RESOURCE" + go "$RESOURCE" "$HOST" "$PORT" > "${HOST}${RESOURCE}" + fi + cleanup + exit 0 fi +echo "${scriptname}: command not found" cleanup + +exit 1 |