changeset 5:1785f86e82cb

bg: initial import
author David Demelier <markand@malikania.fr>
date Tue, 07 Nov 2017 10:57:30 +0100
parents af59db417857
children c92f87d3d3d7
files dmenu_bg
diffstat 1 files changed, 62 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dmenu_bg	Tue Nov 07 10:57:30 2017 +0100
@@ -0,0 +1,62 @@
+#!/bin/sh
+#
+# dmenu_bg -- prompt for a background
+#
+# Copyright (c) 2016-2017 David Demelier <markand@malikania.fr>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+
+dmt_bg_usage()
+{
+    echo "usage: dmenu_bg [directory]" 1>&2;
+    exit 1
+}
+
+if [ -r dmenu.subr ]; then
+    . ./dmenu.subr
+fi
+if [ -r /usr/local/libexec/dmenutools/dmenu.subr ]; then
+    . /usr/local/libexec/dmenutools/dmenu.subr
+fi
+
+# Check for an optional directory.
+if [ $# -ge 1 ]; then
+    directory="$1"
+elif [ -n "${bg_directory}" ]; then
+    directory="${bg_directory}"
+else
+    directory="${XDG_PICTURES_DIR:-${HOME}}"
+fi
+
+# Use user bg_cmd if defined, otherwise find one.
+if [ -z "${bg_cmd}" ]; then
+    if command -v feh > /dev/null 2>&1; then
+        bg_cmd="feh --bg-scale"
+    elif command -v hsetroot > /dev/null 2>&1; then
+        bg_cmd="hsetroot -fill"
+    elif command -v fbsetbg > /dev/null 2>&1; then
+        bg_cmd="fbsetbg"
+    else
+        dmt_fatal "no background manager found"
+        # NOTREACHED
+    fi
+fi
+
+file=$(./dmenu_filesel ${directory})
+
+if [ -n "${file}" ]; then
+    ${bg_cmd} ${file}
+fi
+
+# vim: syntax=sh: