commit d8cfdaa6ebeacf24c6140c181e959fe9b28c2e7a
parent f067a141e31282f2ab14c0c15564b0155409c01c
Author: Anton Konyahin <me@konyahin.xyz>
Date: Sun, 25 Feb 2024 12:59:18 +0300
script for web notes
Diffstat:
M | dsttemp | | | 2 | -- |
A | stnote | | | 22 | ++++++++++++++++++++++ |
M | sttemp | | | 64 | +++++++++++++++++++++++++++++++++++++++++++++++----------------- |
3 files changed, 69 insertions(+), 19 deletions(-)
diff --git a/dsttemp b/dsttemp
@@ -2,8 +2,6 @@
set -eu
-DISPLAY=:0.0
-
export STTEMP_ASK=$(
cat <<'EOF'
ask () {
diff --git a/stnote b/stnote
@@ -0,0 +1,22 @@
+#!/usr/bin/env sh
+
+set -eu
+
+export STTEMP_ASK=$(
+ cat <<'EOF'
+ask () {
+ echo $(dmenu -p "Enter $1" </dev/null)
+}
+EOF
+)
+
+
+export BODY=$(xclip -o)
+
+xdotool key --clearmodifiers "Ctrl+l"
+xdotool key --clearmodifiers "Ctrl+c"
+export URL=$(xclip -o -selection primary)
+xdotool key --clearmodifiers "Escape"
+
+FILE_NAME=$(date '+%Y-%m-%d-%H%M%S')
+sttemp webnote >> "/home/anton/data/notes/web/$FILE_NAME.md"
diff --git a/sttemp b/sttemp
@@ -14,7 +14,8 @@ fill_vars () {
for var in $vars
do
[ -z "$(printenv "$var")" ] &&
- eval "export $var=$(ask "$var")"
+ value="$(ask "$var")" &&
+ eval "export $var=\"$value\""
done
}
@@ -24,39 +25,68 @@ print_templ () {
print_help () {
cat <<EOF
-sttemp [-lhv] [template] - simple template manager
+sttemp - simple template manager
Usage:
- -h print this help
- -l print list of all templates
- -v print all variables from template
- template fill shell-like variables in template file and print his content. Missing environment variable will be asked on stderr.
+ -h Print this help
+ -l Print list of all templates
+ -v name Print all variables from template
+ -d dir Set directory with templates.
+ name Fill shell-like variables in template file and print his content. Missing environment variable will be asked on stderr.
EOF
exit
}
+[ "$#" -lt 1 ] && print_help
-TEMPL_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/sttemp"
-mkdir -p "$TEMPL_DIR"
+while [ "$#" -gt 0 ]; do
+ case "$1" in
+ -h)
+ HELP=YES
+ shift
+ ;;
+ -l)
+ LIST_TEMPL=YES
+ shift
+ ;;
+ -v)
+ PRINT_VAR=YES
+ shift
+ ;;
+ -d)
+ TEMPL_DIR="$2"
+ shift 2
+ ;;
+ *)
+ TEMPL_NAME="$1"
+ shift
+ ;;
+ esac
+done
-[ -n "${STTEMP_ASK:-}" ] && eval "$STTEMP_ASK"
+[ -n "${HELP:-}" ] && print_help
-[ "$#" -lt 1 ] && print_help
+[ -z "${TEMPL_DIR:-}" ] &&
+ TEMPL_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/sttemp" &&
+ mkdir -p "$TEMPL_DIR"
-case "$1" in
- -h) print_help ;;
- -l) ls "$TEMPL_DIR" && exit ;;
- -v) PRINT_VAR=true && shift 1 ;;
-esac
+[ -n "${LIST_TEMPL:-}" ] &&
+ ls "$TEMPL_DIR" &&
+ exit
-TEMPL="$TEMPL_DIR/$1"
+[ -z "${TEMPL_NAME:-}" ] &&
+ echo "You should specify template name" &&
+ exit 1
+
+TEMPL="$TEMPL_DIR/$TEMPL_NAME"
[ ! -f "$TEMPL" ] &&
- echo "Template $1 doesn't exist in $TEMPL_DIR" >&2 &&
+ echo "Template $TEMPL_NAME doesn't exist in $TEMPL_DIR" >&2 &&
exit 1
[ -n "${PRINT_VAR:-}" ] &&
envsubst -v "$(cat "$TEMPL")" &&
exit
+[ -n "${STTEMP_ASK:-}" ] && eval "$STTEMP_ASK"
fill_vars
print_templ