summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/shot73
-rwxr-xr-xscripts/svol19
-rwxr-xr-xscripts/swall6
3 files changed, 73 insertions, 25 deletions
diff --git a/scripts/shot b/scripts/shot
index f99f28d..4bebce2 100755
--- a/scripts/shot
+++ b/scripts/shot
@@ -1,11 +1,11 @@
#!/bin/sh
-
help() {
cat << EOF
-$0: Wrapper script to take screenshots
+${0}: Wrapper script to take screenshots
options:
+ -d [File] Write to File
-s Select the area with the cursor
-h Print this message and exit
@@ -13,16 +13,65 @@ NOTE: save directory is ~/pic/screenshots
EOF
}
-directory="${XDG_CONFIG_HOME:-$HOME}/pics/screenshots"
-[ -d "$directory" ] || { mkdir -p "$directory" || echo "failed to create directory" >&2; }
-filename="$directory"/%b%d::%H%M%S.png
+err() {
+ for line in "$@"; do
+ echo "${line}" >&2
+ done
+
+ exit 1
+}
+
+run() {
+ if ! ${1} > /dev/null 2>&1; then
+ err "${2}"
+ fi
+
+ [ -n "${3}" ] && echo "${3}"
+ exit 0
+}
+
+default_dir="${HOME}"/pics/screenshots
+s_flg=""
+while getopts "d:sh" option; do
+ case "${option}" in
+ d) input="${OPTARG}" ;;
+
+ s) s_flg="1" ;;
-while getopts "sh" option; do
-case $option in
- s) FLG="-fs" ;;
- h) help ; exit 0 ;;
- *) echo "$0 -h for help"; exit 1 ;;
-esac
+ h) help; exit 0 ;;
+
+ *) err "Try '${0} -h' for help" ;;
+ esac
done
-scrot $FLG -z $filename > /dev/null 2>&1 || { echo Screenshot failed; exit 1; }
+shift $((OPTIND - 1))
+
+if [ $# != 0 ];then
+ err "${0}: Invalid usage" \
+ "Try '${0} -h' for help."
+fi
+
+if [ -n "${input}" ]; then
+ case $(file -b --mime-type "${input}") in
+ image/*) outfile="${input}" ;;
+
+ inode/directory) outdir="${input}" ;;
+
+ *) err "Couldn't read given file" ;;
+ esac
+fi
+
+if [ -z "${outfile}" ]; then
+ if [ -z "${outdir}" ]; then
+ [ ! -d "${default_dir}" ] && mkdir -pv "${default_dir}"
+ outdir="${default_dir}"
+ fi
+ outfile="${outdir}"/%b%d::%H%M%S.png
+fi
+
+
+if [ "${s_flg}" = "1" ]; then
+ run "scrot -zs ${outfile}" "Failed to screenshot"
+else
+ run "scrot -z ${outfile}" "Failed to screenshot"
+fi
diff --git a/scripts/svol b/scripts/svol
index ac78040..0f8fa5e 100755
--- a/scripts/svol
+++ b/scripts/svol
@@ -2,7 +2,7 @@
help() {
cat << EOF
-$0: Wrapper script to change volume
+${0}: Wrapper script to change volume
options:
-i [Vol] Increase volume by Vol
@@ -15,7 +15,9 @@ EOF
}
err() {
- echo "$*" >&2
+ for line in "${@}"; do
+ echo "${line}" >&2
+ done
exit 1
}
@@ -23,6 +25,9 @@ run() {
if ! ${1} > /dev/null 2>&1; then
err "${2}"
fi
+
+ [ -n "${3}" ] && echo "${3}"
+ exit 0
}
if ! command -v pactl > /dev/null 2>&1; then
@@ -30,8 +35,7 @@ if ! command -v pactl > /dev/null 2>&1; then
fi
if [ $# != 1 ] && [ $# != 2 ]; then
- err "${0}: Invalid usage
-Try '$0 -h' for help."
+ err "${0}: Invalid usage" "Try '$0 -h' for help."
fi
while getopts "i:d:s:pth" option; do
@@ -39,22 +43,18 @@ while getopts "i:d:s:pth" option; do
i)
run "pactl set-sink-volume @DEFAULT_SINK@ +${OPTARG}%" \
"${0}: Failed to increase volume"
- exit 0
;;
d)
run "pactl set-sink-volume @DEFAULT_SINK@ -${OPTARG}%" \
"${0}: Failed to decrease volume"
- exit 0
;;
s)
run "pactl set-sink-volume @DEFAULT_SINK@ ${OPTARG}%" \
"${0}: Failed to set volume"
- exit 0
;;
t)
run "set-sink-volume @DEFAULT_SINK@ toggle" \
"${0}: Failed to toggle volume"
- exit 0
;;
p)
if ! pactl get-sink-volume @DEFAULT_SINK@ 2>/dev/null; then
@@ -70,5 +70,4 @@ while getopts "i:d:s:pth" option; do
esac
done
-err "${0}: Invalid usage
-Try '$0 -h' for help."
+err "${0}: Invalid usage" "Try '$0 -h' for help."
diff --git a/scripts/swall b/scripts/swall
index 0b0a088..1f231cd 100755
--- a/scripts/swall
+++ b/scripts/swall
@@ -24,6 +24,8 @@ run() {
if ! ${1} > /dev/null 2>&1; then
err "${2}"
fi
+
+ [ -n "${3}" ] && echo "${3}"
exit 0
}
@@ -70,6 +72,4 @@ fi
[ -z "${image}" ] && err "${0}: No image file found"
-run "xwallpaper --zoom ${image}" "${0}: Failed to set wallpaper"
-
-echo "${image}"
+run "xwallpaper --zoom ${image}" "${0}: Failed to set wallpaper" "${image}"