aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgsocial-cli.sh102
1 files changed, 58 insertions, 44 deletions
diff --git a/gsocial-cli.sh b/gsocial-cli.sh
index 75d3d4a..e4ac11d 100755
--- a/gsocial-cli.sh
+++ b/gsocial-cli.sh
@@ -15,9 +15,7 @@ LICENSE="The Drunken BEER License v 1.1 (https://git.p4g.club/git/beer/about)"
# usage
usage () {
-test $# = 0 || printf "%s %s\\n" "${SCRIPTNAME}" "$@"
cat << EOF | fold -s
-
by ${AUTHOR}
License: ${LICENSE}
@@ -286,22 +284,15 @@ tget () {
verify_credentials
curl -s -u "$USER:$PASSWORD" "${data_api}" "${get_api}" \
> "${TIMELINEF}"
-
- SID="$(sed '/^[ \t] <id>/ !d; s/^[ \t]*<id>//; s/<\/id>$//' \
- "${TIMELINEF}")"
- ST="screen_name>"
- SNAME="$(sed '/^[ \t] .<'${ST}'/ !d; s/^[ \t]*<'${ST}'//; s/<\/'${ST}'$//' \
- "${TIMELINEF}")"
- UNAME="$(sed '/^[ \t] .<name>/ !d; s/^[ \t]*<name>//; s/<\/name>$//' \
- "${TIMELINEF}")"
- TEXT="$(sed '/^[ \t] <text>/ !d; s/^[ \t]*<text>//; s/<\/text>$//' \
- "${TIMELINEF}")"
- SSOURCE="$(sed '/^[ \t].<source>/ !d; s/^[ \t]*<source>//; s/<\/source>$//' \
- "${TIMELINEF}")"
- CT="created_at>"
- CREATED="$(sed '/^[ \t].<'${CT}'/ !d; s/^[ \t]*<'${CT}'//; s/<\/'${CT}'//;' \
- "${TIMELINEF}")"
+ SID="$(sed '/^[ \t] <id>/ !d; s/ *<[^>]*> *//g' "${TIMELINEF}")"
+ SNAME="$(sed '/^[ \t] .<screen_name>/ !d; s/ *<[^>]*> *//g' "${TIMELINEF}")"
+
+ UNAME="$(sed '/^[ \t] .<name>/ !d; s/ *<[^>]*> *//g' "${TIMELINEF}")"
+ TEXT="$(sed '/^[ \t] <text>/ !d; s/ *<[^>]*> *//g' "${TIMELINEF}")"
+ SSOURCE="$(sed '/^[ \t].<source>/ !d; s/ *<[^>]*> *//g' "${TIMELINEF}")"
+ CREATED="$(sed '/^[ \t].<created_at>/ !d; s/ *<[^>]*> *//g' "${TIMELINEF}")"
+
test -z "${SID}" \
&& printf "\\e%swarning:\\e%s command returned an empty output\\e[0m\\n" \
"${warn_c}" "${info_c}" \
@@ -544,7 +535,6 @@ DN="/dev/null"
XDGCONFIG="${XDG_HOME_CONFIG:=${HOME}/.config}"
CONFIGD="${XDGCONFIG}/${SCRIPTNAME}"
GSF="${CONFIGD}/${SCRIPTNAME}_config"
-
test ! -d "${CONFIGD}" && mkdir -p "${CONFIGD}"
test ! -f "${GSF}" && create_gsf
test "$#" -lt 1 && usage "$@"
@@ -556,6 +546,56 @@ elif [ "$1" = "show" ]; then
SHOWARGS="$3"
fi
+# show command
+case "${SHOW}" in
+ settings | config)
+ if [ -z "${SHOWARGS}" ]; then
+ sed '/^#/ d; s/[ \t]*$//g' "${GSF}"
+ else
+ sed '/'"${SHOWARGS}"'/ !d' "${GSF}"
+ fi
+ ;;
+ accounts | profiles)
+ if [ -z "${SHOWARGS}" ]; then
+ ACCONFIGS="$(find "${CONFIGD}" | grep "\.config$")"
+ for acconfigs in $ACCONFIGS; do
+ printf "\\n\\e%s" "${good_c}"
+ sed '/\.config/ !d; s/# gsocial-cli -- //g' "${acconfigs}"
+ printf "\\e[0m"
+ sed '/NODE/ !d; s/NODE=//; s/;$//' "${acconfigs}" | base64 -d -
+ printf "USER="
+ sed '/USER/ !d; s/USER=//; s/;$//' "${acconfigs}" | base64 -d -
+ printf "PASSWORD="
+ sed '/PASSWORD/ !d; s/PASSWORD=//; s/;$//' "${acconfigs}" | base64 -d -
+ printf "\\n"
+ done
+ else
+ ACCONFIGS="${CONFIGD}/${SHOWARGS}.config"
+ test ! -f "${ACCONFIGS}" \
+ && printf "\\e%sfatal:\\e[0m account %s not configured" \
+ "${diee_c}" "${ACCCONFIGS}" \
+ && exit 0
+
+ printf "\\n\\e%s" "${good_c}"
+ sed '/\.config/ !d; s/# gsocial-cli -- //g' "${ACCONFIGS}"
+ printf "\\e[0m"
+ sed '/NODE/ !d; s/NODE=//; s/;$//' "${ACCONFIGS}" | base64 -d -
+ printf "USER="
+ sed '/USER/ !d; s/USER=//; s/;$//' "${ACCONFIGS}" | base64 -d -
+ printf "PASSWORD="
+ sed '/PASSWORD/ !d; s/PASSWORD=//; s/;$//' "${ACCONFIGS}" | base64 -d -
+ printf "\\n"
+ fi
+ ;;
+#TODO: isn't is obvious?
+ history | cache)
+ echo "hist"
+ ;;
+#TODO: again, obvious
+ commands)
+ echo "comm"
+ ;;
+esac
# obtain general settings
sed '/^#/ d; s/[ \t]*$//g' "${GSF}" > "${GSFT}"
@@ -576,32 +616,6 @@ text_c="$(sed '/text_c=/ !d; s/text_c=//' "${THFT}")"
meta_c="$(sed '/meta_c=/ !d; s/meta_c=//' "${THFT}")"
myself_c="$(sed '/myself_c=/ !d; s/myself_c=//' "${THFT}")"
-# show stuff
-case "${SHOW}" in
- settings | config)
-if [ -z "${SHOWARGS}" ]; then
- sed '/^#/ d; s/[ \t]*$//g' "${GSF}"
-else
- sed '/'"${SHOWARGS}"'/ !d' "${GSF}"
-fi
- ;;
-accounts | profiles)
- temporal="$(mktemp -p "${TMPDIR}")"
- ACCCONFIGS="$(find "${CONFIGD}" | grep "\.config$")"
- for accconfigs in $ACCCONFIGS; do
- cat $accconfigs #>> $temporal;
- done
-
- # sed '/^#/ d; s/[ \t]*$//g' "${temporal}"
- ;;
-history | cache)
- echo "hist"
- ;;
-commands)
- echo "comm"
- ;;
-esac
-
# provide account or use default
if [ "$1" = "-a" ];then
ACCNAME="$2" ;