-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathtwidge-sh
executable file
·91 lines (79 loc) · 2.33 KB
/
twidge-sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
# twidge-sh: customized interactive twidge shell
# Copyright: (C) 2010 Florian Baumann <[email protected]>
# License: GPL-3 <http://www.gnu.org/licenses/gpl-3.0.txt>
# Date: Monday 2010-10-04
### initial settings & security ###############################################
# need some general security checks and generate settings
#
# get config if available
if [ -r $HOME/.twidgerc ]; then
twidgerc=$HOME/.twidgerc
else
echo "$HOME/.twidgerc not found!"
echo "try: 'twidge setup' to fix it."
exit
fi
# check username
if ! grep -q "screen_name" $twidgerc ; then
echo "error by getting username from $twidgerc"; exit 1
fi
# check service
if ! grep -q -e "^urlbase:.*$" $twidgerc ; then
echo "error by getting microblogging-service from $twidgerc"; exit 1
fi
# create new shell with specific config
[ "$0" = 'bash' ] || exec /usr/bin/env bash --rcfile "$0" "$@"
# include user's .bashrc file
[ -r ~/.bashrc ] && {
pushd ~ > /dev/null
. .bashrc
popd > /dev/null
}
### completion and aliases ####################################################
# read standard commands and create aliases for new prompt
# defined aliases will automatically be completed
# usage:
# user@twitter> lsrecent
#
for x in $(twidge lscommands | tail --lines=+4 | cut -f1 -d' '| grep "^$cur")
do
alias $x="twidge $x"
done
# read local aliases in .twidgerc
# for example:
# [alias]
# recent: lsrecent -u
# replies: lsreplies -u
#
OLDIFS=$IFS; IFS=$'\n'
for y in $(cat $twidgerc | sed -n -e '/\[alias\]/,/\[.*\]/s/:/:/p')
do
key=$(echo $y | cut -d : -f 1)
command=$(echo $y | cut -d : -f 2-)
alias ${key}="twidge $command"
done
IFS=$OLDIFS
# display commands by "help"
alias help="twidge lscommands"
### customized prompt #########################################################
# create microblogging prompt
# for example: user@twitter>
#
PS1='$(get_user)@$(get_services)> '
# get username from config
get_user() {
if fgrep -q "screen_name" $twidgerc ; then
fgrep "screen_name" $twidgerc | cut -d \" -f 8
elif fgrep -q "username:" $twidgerc; then
fgrep "username:" | awk '{print $NF}'
fi
}
# get configured service for prompt
get_services() {
if grep -q -e "^urlbase:.*twitter.com$" $twidgerc; then
echo "twitter"
elif grep -q -e "^urlbase:.*identi.ca$" $twidgerc; then
echo "identica"
fi
}