Compare commits

...

2 Commits
main ... main

Author SHA1 Message Date
rick a06e19c584 no config file required now 2021-07-25 18:37:19 +05:30
r1k a930b31789 Merge pull request 'main' (#3) from g1n/twtxt-c:main into main
Reviewed-on: r1k/twtxt-c#3
2021-07-25 09:07:04 +00:00
1 changed files with 107 additions and 12 deletions

119
twtxt-c
View File

@ -3,6 +3,16 @@
PROGNAME=${0##*/}
VERSION="0.0.1"
# config variables
# you can set these according to your choice
nick=$USER # change this to your desired nick
path_to_twtxt=$HOME/twtxt.txt
url="https://example.com/twtxt.txt"
# list of getwtxt registries api
reg1="https://twtxt.envs.net/api/plain/"
reg2="https://twtxt.tilde.institute/api/plain/"
error_exit() {
printf "%s: %s\n" "$PROGNAME" "${1:-"Unknown Error"}" >&2
exit 1
@ -36,6 +46,8 @@ Commands:
}
read_config () {
declare -A v=()
while read -r var value; do
@ -48,18 +60,101 @@ case $1 in
-* | --*)
usage; error_exit "unknown option $1" ;;
init)
read -p "Your desired nickname [$USER]: " nick
nick=${nick:-"$USER"}
read -p "Type path to your twtxt [/home/$USER/twtxt.txt]: " path_to_twtxt
path_to_twtxt=${path_to_twtxt:-"/home/$USER/twtxt.txt"}
echo "" >> $path_to_twtxt
read -p "Type path to your twtxt config folder [/home/$USER/.config/twtxt-c/]: " config
config=${config:-"/home/$USER/.config/twtxt-c/"}
mkdir -p $config
read -p "URL to twtxt [https://example.com/twtxt.txt]: " url
url=${url:-"https://example.com/twtxt.txt"}
printf "[twtxt]\n nick = %s\n twtfile = %s\n url = %s\n" "$nick" "$path_to_twtxt" "$url" >> $config/config
printf "https://twtxt.envs.net/api/plain/\nhttps://twtxt.tilde.institute/api/plain/\n" > $config/registry
printf "The config variables are stored in this script itself \n Enter yes if you want to open it now \n Enter no if you want to edit it yourself later\n"
while true; do
read -rp "$2 " yn
case $yn in
[Yy]*) open=1; break;;
[Nn]*) open=0; break;;
*) echo "Please answer yes or no"
esac
done
if [[ $open == 1 ]]
then {
if which twtxt-c &> /dev/null
then
scriptpath=$(which twtxt-c)
else {
read -p "Path to this script [`pwd`/twtxt-c]" scriptpath
scriptpath=${scriptpath:-"`pwd`/twtxt-c"}
}
fi
if [ -z "$EDITOR" ]
then
{
if which vim &> /dev/null
then
vim $scriptpath
elif which nvim &> /dev/null
then
nvim $scriptpath
elif which emacs &> /dev/null
then
emacs -nw $scriptpath
elif which nano &> /dev/null
then
nano $scriptpath
else
echo " EDITOR variable is empty and vim, neovim, emacs and nano not found. please open this script using your preferred text editor and set the config variables"
fi
echo "Now you can tweet using twtxt-c tweet <tweet>"
}
else
$EDITOR $scriptpath
fi
}
else
echo "Please edit the script and set nick, path to twtxt file and url for twtxt file"
fi
echo "would you like to copy this script to $HOME/.local/bin [yes/no]"
while true; do
read -rp "$3 " yn
case $yn in
[Yy]*) copy=1; break;;
[Nn]*) copy=0; break;;
*) echo "Please answer yes or no"
esac
done
if [[ $copy == 1 ]]
then {
# give warning if path not ok
if [[ $PATH != *"$HOME/.local/bin"* && $PATH != *"~/.local/bin"* ]]
then
echo " Warning: $HOME/.local/bin is not in PATH "
fi
# checking for scriptpath
if which twtxt-c &> /dev/null
then
echo "already present"
elif [[ -z "$scriptpath" ]]
then {
read -p "Path to this script [`pwd`/twtxt-c]" scriptpath
scriptpath=${scriptpath:-"`pwd`/twtxt-c"}
cp $scriptpath $HOME/.local/bin/
}
else
cp $scriptpath $HOME/.local/bin/
fi
}
fi
printf "Would you like to set the following aliases \n ttc=twtxt-c timeline\n twtc=twtxt-c tweet\n"
while true; do
read -rp "$3 " yn
case $yn in
[Yy]*) als=1; break;;
[Nn]*) als=0; break;;
*) echo "Please answer yes or no"
esac
done
if [[ $als == 1 ]]
then {
read -p "Path to alias file [$HOME/.bash_aliases]" alspath
alspath=${alspath:-"$HOME/.bash_aliases"}
echo "alias ttc='twtxt-c timeline'" >> $alspath
echo "alias twtc='twtxt-c tweet'" >> $alspath
}
fi
;;
tweet)
export config=/home/$USER/.config/twtxt-c/config