rearrange code to remove redundancies

master
KatolaZ 6 years ago
parent 22a92b1d44
commit 3f4090d1dd
  1. 53
      gophed

@ -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

Loading…
Cancel
Save