Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
linux4life798 committed Sep 2, 2016
1 parent 5d194ce commit 6302c20
Showing 1 changed file with 56 additions and 42 deletions.
98 changes: 56 additions & 42 deletions xmppcmd.bash
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,42 @@ XMPP_CMDS+=( send send_stanza_iq stanza_pubsub , )
XMPP_CMDS+=( list_nodes , )
XMPP_CMDS+=( recv )

# Show the help message
alias xhelp='xmpphelp'
xmpphelp() {

# check args
if (( $# < 0 )) || [[ "$1" =~ --help ]] || [[ "$1" =~ -h ]]; then
echo "Usage: xmpphelp [command1 [command2 [...]]]"
echo "Get help with one or many commands"
return 0
fi

if [ $# -gt 0 ]; then
# Get help for certain commands
for i; do
echo "$ $i --help"
$i --help
echo
done
else
# Print help message
echo "Tip: You can use $(font yellow)xhelp$(font off) in place of xmpphelp."
# List off all commands
font bold
echo "Valid commands:"
font off
for i in ${XMPP_CMDS[@]}; do
if [ "$i" = "," ]; then
echo
else
echo " $i"
fi
done
fi
}


# DEPRECIATED method
# Using the commandline utility sendxmpp
# echo "raw xml" | send
Expand Down Expand Up @@ -161,11 +197,16 @@ qualify_jid() {
fi
}

# Generate a unique id
newid() {
echo "xmppsend$RANDOM"
}


##########################################################################
# XML Stanza Manipulation Primitives #
##########################################################################


# Sends an EOF to terminate a stream of stanzas
eof() {
printf ""
Expand Down Expand Up @@ -232,8 +273,6 @@ send_stanza_iq() {
stanza_iq "$typ" "$id" "$to" | send "$id"
}



# stanza_pubsub [owner]
stanza_pubsub() {

Expand Down Expand Up @@ -264,45 +303,10 @@ stanza_query() {
fi
}

# Generate a unique id
newid() {
echo "xmppsend$RANDOM"
}

# Show the help message
alias xhelp='xmpphelp'
xmpphelp() {

# check args
if (( $# < 0 )) || [[ "$1" =~ --help ]] || [[ "$1" =~ -h ]]; then
echo "Usage: xmpphelp [command1 [command2 [...]]]"
echo "Get help with one or many commands"
return 0
fi

if [ $# -gt 0 ]; then
# Get help for certain commands
for i; do
echo "$ $i --help"
$i --help
echo
done
else
# Print help message
echo "Tip: You can use $(font yellow)xhelp$(font off) in place of xmpphelp."
# List off all commands
font bold
echo "Valid commands:"
font off
for i in ${XMPP_CMDS[@]}; do
if [ "$i" = "," ]; then
echo
else
echo " $i"
fi
done
fi
}
##########################################################################
# Runtime Config Interface #
##########################################################################

# Set whether xml pretty printing is on or off
pretty() {
Expand Down Expand Up @@ -456,6 +460,11 @@ get_config() {
echo "Version $XMPPCMD_VERSION"
}


##########################################################################
# XMPP/PubSub Interface Level #
##########################################################################

# message <to> <message_body | ->
message() {
local to=$(qualify_jid $1)
Expand Down Expand Up @@ -872,7 +881,9 @@ set_vcard() {
send_stanza_iq set ""
}


##########################################################################
# High Level Functions #
##########################################################################

list_nodes() {
Expand All @@ -882,7 +893,9 @@ list_nodes() {
echo
}


##########################################################################
# BASH Completion Handlers #
##########################################################################

_NODES_CACHE=( )
Expand Down Expand Up @@ -979,10 +992,11 @@ _get_item() {
esac
}


##########################################################################
# Init Routine #
##########################################################################


# Unset all DEFAULT_XMPP_* Settings for Reimporting xmpprc #
unset DEFAULT_XMPP_USER
unset DEFAULT_XMPP_PASS
Expand Down

0 comments on commit 6302c20

Please sign in to comment.