Add config file for pasta
Instead of using values hard-coded into the script, read from ~/.config/pastarc. Prompt user to configure if file does not exist Test for import command as well as xclip in pasta
This commit is contained in:
parent
b3791d5d4d
commit
93d7497e7d
43
src/pasta.sh
43
src/pasta.sh
|
@ -4,17 +4,39 @@
|
||||||
# author: Hiltjo Posthuma <hiltjo@codemass.org>, Dylan Lom <djl@dylanlom.com>
|
# author: Hiltjo Posthuma <hiltjo@codemass.org>, Dylan Lom <djl@dylanlom.com>
|
||||||
# see-also: https://codemadness.org/paste-service.html
|
# see-also: https://codemadness.org/paste-service.html
|
||||||
|
|
||||||
sshdomain="djl@p.dlom.cc"
|
configpath="$HOME/.config/pastarc"
|
||||||
destpath="/usr/local/www/p.dlom.cc"
|
|
||||||
destdomain="http://p.dlom.cc"
|
|
||||||
|
|
||||||
argv0="$0"
|
argv0="$0"
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
printf "SSH Domain: "; read sshdomain
|
||||||
|
printf "Remote destination: "; read destpath
|
||||||
|
printf "Remote URL: "; read destdomain
|
||||||
|
printf "sshdomain='$sshdomain'\ndestpath='$destpath'\ndestdomain='$destdomain'\n" > "$configpath"
|
||||||
|
}
|
||||||
|
|
||||||
|
firsttimesetup() {
|
||||||
|
echo "Configuration file ($configpath) not found!"
|
||||||
|
confirm "Create?" || exit
|
||||||
|
test -d ~/.config || mkdir -p ~/.config
|
||||||
|
setup
|
||||||
|
}
|
||||||
|
|
||||||
|
isinstalled() {
|
||||||
|
echo "$PATH"
|
||||||
|
command -v "$1" > /dev/null \
|
||||||
|
&& return 0 \
|
||||||
|
|| (echo "ERROR: Executable '$1' not found!"; return 1)
|
||||||
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "usage: $argv0 [-p|-c|-g] [-x] filename"
|
echo "usage: $argv0 [-p|-c|-g] [-x] filename" > /dev/stderr
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test -f "$configpath" \
|
||||||
|
&& . "$configpath" \
|
||||||
|
|| firsttimesetup
|
||||||
|
|
||||||
while [ "$#" -gt 1 ]; do
|
while [ "$#" -gt 1 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
'-p') png='true'; ;;
|
'-p') png='true'; ;;
|
||||||
|
@ -30,11 +52,11 @@ name="$1"
|
||||||
[ -z "$name" ] && usage
|
[ -z "$name" ] && usage
|
||||||
|
|
||||||
if truthy "$xclip"; then
|
if truthy "$xclip"; then
|
||||||
command -v xclip > /dev/null \
|
isinstalled xclip || exit 1
|
||||||
|| (echo "ERROR: xclip not found" && exit 1) \
|
|
||||||
&& (echo "$destdomain/$name" | \
|
echo "$destdomain/$name" | \
|
||||||
tr -d '\n' | \
|
tr -d '\n' | \
|
||||||
xclip -selection clipboard)
|
xclip -selection clipboard
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if truthy "$get"; then
|
if truthy "$get"; then
|
||||||
|
@ -45,6 +67,7 @@ fi
|
||||||
if truthy "$concat"; then
|
if truthy "$concat"; then
|
||||||
ssh "$sshdomain" "cat >> $destpath/$name"
|
ssh "$sshdomain" "cat >> $destpath/$name"
|
||||||
else
|
else
|
||||||
|
isinstalled import || exit 1
|
||||||
(truthy "$png" && import png:- || cat) | \
|
(truthy "$png" && import png:- || cat) | \
|
||||||
ssh "$sshdomain" "cat > $destpath/$name"
|
ssh "$sshdomain" "cat > $destpath/$name"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue