diff options
Diffstat (limited to 'scripts/gui')
| -rwxr-xr-x | scripts/gui/br | 32 | ||||
| -rwxr-xr-x | scripts/gui/nsend | 56 | ||||
| -rwxr-xr-x | scripts/gui/sclip | 69 | ||||
| -rwxr-xr-x | scripts/gui/sdev | 49 | ||||
| -rwxr-xr-x | scripts/gui/shot | 37 | ||||
| -rwxr-xr-x | scripts/gui/sslock | 67 | ||||
| -rwxr-xr-x | scripts/gui/swall | 56 |
7 files changed, 199 insertions, 167 deletions
diff --git a/scripts/gui/br b/scripts/gui/br index 474b1b1..428e24b 100755 --- a/scripts/gui/br +++ b/scripts/gui/br @@ -1,6 +1,6 @@ #!/bin/sh -. slib +. "lib_common.sh" help() { cat << EOF @@ -9,33 +9,25 @@ options: [link] Open link -h Print this message and exit -NOTE: bookmarks file is located at ~/.config/sites/bookmarks +NOTE: bookmarks file is located at ~/.config/sites/bookmarks.txt EOF - exit 0 } -alias dmenucmd="dmenu -bw 1 -c -g 1 -l 25" - -[ -z "${BROWSER}" ] && browser="qutebrowser" || browser="${BROWSER}" +[ -z "${BROWSER}" ] && BROWSER="firefox" if [ "${#}" -eq 0 ]; then + bookmark_path="${XDG_CONFIG_HOME:-$HOME/.config}/sites/bookmarks.txt" + [ -e "${bookmark_path}" ] || err "Couldn't find bookmarks file" - link_file="${XDG_CONFIG_HOME:-$HOME/.config}/sites/bookmarks.txt" - - check_program "dmenu" + . "lib_handle.sh" - [ -z "${XDG_HOME_CONFIG}" ] || link_file="${XDG_HOME_CONFIG}"/sites/bookmarks.txt - [ -e "${link_file}" ] || err "Couldn't find bookmarks file" + link=$(< "${bookmark_path}" menu_handle center) - link=$(< "${link_file}" dmenucmd) - - [ -z "${link}" ] || "${browser}" "${link}" + [ -z "${link}" ] || "${BROWSER}" "${link}" +fi -elif [ "${#}" -eq 1 ]; then - [ "${1}" = "-h" ] && help +[ "${#}" -ne 1 ] && invalid_use +[ "${1}" = "-h" ] && help - "${browser}" "${1}" -else - invalid_use -fi +"${BROWSER}" "${1}" diff --git a/scripts/gui/nsend b/scripts/gui/nsend index 1bfc1f4..e1cbd78 100755 --- a/scripts/gui/nsend +++ b/scripts/gui/nsend @@ -1,34 +1,44 @@ #!/bin/sh -. slib +. "lib_common.sh" +. "lib_handle.sh" help() { cat << EOF -${0}: Wrapper script to send notifications +${argv0}: Send notifications options: - -s [Name] [Msg] Send Msg with Name - -s [Msg] Send Msg Without Name + -s [Msg] Send Msg + -t [Time] Disappear after Time (in second) -h Print this message and exit -EOF +Note: time must be between 0 and 300, +by default time is set to unlimited. +EOF exit 0 } -case "${#}" in -1) - [ "${1}" = "-h" ] && help - invalid_use -;; -2) - [ "${1}" = "-s" ] || invalid_use - notification_string="${2}" -;; -3) - [ "${1}" = "-s" ] || invalid_use - notification_string="${2}: ${3}" -;; -*) invalid_use ;; -esac - - -send_notification "${notification_string}" +[ "${#}" -eq 0 ] && invalid_use + +time=-1 +while getopts "s:t:h" option; do + case "${option}" in + s) msg="${OPTARG}" ;; + t) + time="${OPTARG}" + + case "${time}" in + ''|*[!0-9]*) err "Not a number: ${time}" ;; + esac + + [ "${time}" -gt 300 ] && err "Out of range: ${time}" + ;; + h) help ;; + + *) invalid_use -h ;; + esac +done + +shift $((OPTIND - 1)) +[ ${#} != 0 ] && invalid_use + +notify_handle send "${time}" "${msg}" diff --git a/scripts/gui/sclip b/scripts/gui/sclip index 4854aa1..56ea57f 100755 --- a/scripts/gui/sclip +++ b/scripts/gui/sclip @@ -1,71 +1,72 @@ #!/bin/sh -. slib +. "lib_common.sh" +. "lib_handle.sh" help() { cat << EOF -${0}: print the clipboard content +${progname}: print the clipboard content options: - -h Print this message and exit -s Do not send notifications -c [text] Copy text to clipboard -f [file] Copy content of file into clipboard -i Copy standart input into clipboard + -h Print this message and exit EOF - exit 0 } -check_program "xclip" +clipboard_handle check_program + +if [ "${#}" -eq 0 ]; then + clipboard_handle get-clipboard + exit $? +fi -i_flg=0 +read_stdin=0 silent=0 while getopts "f:c:sih" option; do case "${option}" in f) filepath="${OPTARG}" ;; - c) input="${OPTARG}" ;; - s) silent=1 ;; - - i) i_flg=1 ;; - + i) read_stdin=1 ;; h) help ;; *) invalid_use -h ;; esac done - shift $((OPTIND - 1)) [ "${#}" -ne 0 ] && invalid_use if [ -n "${filepath}" ]; then - mime_type=$(file --mime-type -b "${filepath}") - - if [ "${silent}" -eq 1 ]; then - run "xclip -selection clipboard -t ${mime_type} -i ${filepath}" - fi + mime_type=$(file_handle get-mime_type "$filepath") || { + err "Failed to detect mime type"; exit 1;} - run --success-notify "${filepath} copied" \ - --failure-notify "${filepath} failed to copy" \ - "xclip -selection clipboard -t ${mime_type} -i ${filepath}" -fi + clipboard_handle file "${mime_type}" "${filepath}" + status=$? -[ "${i_flg}" -eq 1 ] && input=$(cat) +else + [ -z "$input" ] && [ "$read_stdin" -eq 1 ] && input=$(cat) + [ -z "$input" ] && err "Empty input" -if [ -n "${input}" ]; then - # Don't use `run` since pipes are used - printf '%s' "${input}" | xclip -selection clipboard + printf '%s' "${input}" | clipboard_handle text + status=$? +fi - if [ $? -eq 0 ]; then - [ "${silent}" -eq 0 ] && send_notification "${argv0}:" "'${input}' copied" - exit 0 +if [ "${silent}" -eq 0 ]; then + if [ "${status}" -eq 0 ]; then + if [ -n "${filepath}" ]; then + notify_handle "Copied file: ${filepath}" + else + notify_handle "Copied text" + fi + else + if [ -n "${filepath}" ]; then + notify_handle "Failed to copy file: ${filepath}" + else + notify_handle "Failed to copy text" + fi fi - - [ "${silent}" -eq 0 ] && send_notification "${argv0}:" "'${input}' failed to copy" - - exit 1 fi - -run "xclip -o -selection clipboard" diff --git a/scripts/gui/sdev b/scripts/gui/sdev new file mode 100755 index 0000000..340bdb1 --- /dev/null +++ b/scripts/gui/sdev @@ -0,0 +1,49 @@ +#!/bin/sh + +. "lib_common.sh" +. "lib_handle.sh" + +help() { +cat << EOF +${0}: Disable and Enable devices +options: + -e [dev] Enable dev + -d [dev] Disable dev + -t [dev] Toggle dev + -l List devices + -h Print this message and exit + +Note: Nondescriptive inputs may disable/enable unwanted devices. +EOF +exit 0 +} + +input_device_handle check_program + +get_id() { + id=$(input_device_handle get-id "$1") || exit 1 + printf '%s\n' "$id" +} + +while getopts "e:d:t:lh" option; do + case "${option}" in + e) run "input_device_handle enable $(get_id ${OPTARG})" ;; + d) run "input_device_handle disable $(get_id ${OPTARG})" ;; + t) + id=$(get_id ${OPTARG}) + if input_device_handle is_enabled "${id}"; then + input_device_handle disable "${id}" + else + input_device_handle enable "${id}" + fi + exit $? + ;; + l) run "input_device_handle list" ;; + h) help ;; + + *) invalid_use -h ;; + + esac +done + +invalid_use diff --git a/scripts/gui/shot b/scripts/gui/shot index 712f60b..a133c16 100755 --- a/scripts/gui/shot +++ b/scripts/gui/shot @@ -1,6 +1,7 @@ #!/bin/sh -. slib +. "lib_common.sh" +. "lib_handle.sh" help() { cat << EOF @@ -8,29 +9,26 @@ ${0}: Wrapper script to take screenshots options: -d [File] Write to File -s Select the area with the cursor + -w Select the area with the cursor -h Print this message and exit -NOTE: save directory is ~/pics/screenshot +NOTE: save directory is ~/media/photo/screenshot EOF - exit 0 } -check_program "scrot" - +screenshot_handle check_program default_dir="${XDG_SCREENSHOT_DIR:-${HOME}/media/photo/screenshot}" -s_flg="" -while getopts "d:sh" option; do +mode="fullscreen" +while getopts "d:swh" option; do case "${option}" in - d) input="${OPTARG}" ;; - - s) s_flg="1" ;; - - h) help ;; - - *) invalid_use -h ;; + d) input="${OPTARG}" ;; + s) mode="select" ;; + w) mode="focused-window" ;; + h) help ;; + *) invalid_use -h ;; esac done @@ -48,12 +46,13 @@ outfile="${input}" [ -d "${input}" ] && outfile="${input}/$(date '+%b%d::%H%M%S').png" if [ ! -e "$(dirname "${outfile}")" ]; then - mkdir -p "$(dirname "${outfile}")" > /dev/null 2>&1 \ - || err "Failed to create directory" + mkdir -p "$(dirname "${outfile}")" || + err "Failed to create directory ${outfile}" fi -if [ "${s_flg}" = "1" ]; then - run --reload-compositor "scrot -zs ${outfile}" "${outfile}" +if [ "${mode}" = "select" ]; then + run --no-exit --reload-compositor \ + "screenshot_handle ${mode} ${outfile}" && echo "${outfile}" else - run "scrot -z ${outfile}" "${outfile}" + screenshot_handle "${mode}" "${outfile}" && echo "${outfile}" fi diff --git a/scripts/gui/sslock b/scripts/gui/sslock index 26ba2cf..8a3284e 100755 --- a/scripts/gui/sslock +++ b/scripts/gui/sslock @@ -1,59 +1,44 @@ #!/bin/sh -. slib +. "lib_common.sh" +. "lib_handle.sh" help() { cat << EOF -${0}: Wrapper script to take screenshots +${0}: Lock screen options: - -n Black screen - -b Blur - -c Take the current state of the desktop + -n Black screen lock -h Print this message and exit EOF - exit 0 } -check_program "slock" - -blur=0 -set_current_state=0 -current_wallpaper="${XDG_CACHE_HOME:-$HOME/.cache}/wallpaper/current" -while getopts "bcnh" option; do - case "${option}" in - b) - check_program "mogrify" "imagemagick must be installed" - blur=1 ;; - - c) - check_program "scrot" - set_current_state=1 - ;; - n) - slock - exit 0;; - - h) help ;; - - *) invalid_use -h ;; +trap 'rm -f "${lock_image}"' EXIT INT TERM HUP - esac -done - -shift $((OPTIND - 1)) +if [ "${#}" -eq 1 ]; then + [ "${1}" = "-h" ] && help + [ "${1}" = "-n" ] || invalid_use + screenlock_handle + exit 0 +fi -[ "${#}" -eq 0 ] || invalid_use +[ "${#}" -ne 0 ] && invalid_use -background="/tmp/$(date '+%b%d::%H%M%S').png" +mode=$(printf "Blank\nBlur\nWallpaper" | menu_handle default) +if [ "${mode}" = "Blank" ]; then + screenlock_handle + exit 0 +fi -if [ "$set_current_state" -eq 0 ]; then - # Avoid distorting the wallpaper when calling `mogrify` - cp "${current_wallpaper}" "${background}" -else - scrot -z "${background}" +lock_image=$(get_random_filename .png) +if [ "${mode}" = "Blur" ]; then + screenshot_handle fullscreen "${lock_image}" + image_handle blur "${lock_image}" fi -[ "${blur}" -eq 1 ] && mogrify -blur 0x8 "${background}" +if [ "${mode}" = "Wallpaper" ]; then + current_wallpaper="${XDG_CACHE_HOME:-$HOME/.cache}/wallpaper/current" + cp "${current_wallpaper}" "${lock_image}" +fi -slock -f "${background}" +screenlock_handle "${lock_image}" diff --git a/scripts/gui/swall b/scripts/gui/swall index a225481..5f22ec8 100755 --- a/scripts/gui/swall +++ b/scripts/gui/swall @@ -1,6 +1,7 @@ #!/bin/sh -. slib +. "lib_common.sh" +. "lib_handle.sh" help() { cat << EOF @@ -12,58 +13,53 @@ options: NOTE: default directory is ~/.local/share/wallpapers A symlink at ~/.cache/wallpapers/current is created pointing to the selected wallpaper. - EOF - exit 0 } -check_program "xwallpaper" - +wallpaper_handle check_program SYMLINK="${XDG_CACHE_HOME:-$HOME/.cache}/wallpaper/current" -if [ "${#}" = 0 ]; then - input="${XDG_DATA_HOME:-$HOME/.local/share}/wallpapers" -elif [ "${#}" != 1 ] && [ "${#}" != 2 ]; then - invalid_use -fi +[ "${#}" -eq 0 ] && input="${XDG_DATA_HOME:-$HOME/.local/share}/wallpapers" +[ "${#}" -gt 2 ] && invalid_use -while getopts "hcld:" option; do +while getopts "cd:h" option; do case "${option}" in c) - unlink "${SYMLINK}" - run --reload-compositor "xwallpaper --clear" ;; - + rm -f "${SYMLINK}" + run --reload-compositor "wallpaper_handle clear" + ;; d) input="${OPTARG}" ;; - h) help ;; *) invalid_use -h ;; - esac done - shift $((OPTIND - 1)) [ "${#}" != 0 ] && invalid_use if [ -n "${input}" ]; then - case $(file -L -b --mime-type "${input}") in - image/*) image="${input}" ;; - - inode/directory) waldir="${input}" ;; - - *) err "Couldn't read given file" ;; - esac + if [ -d "${input}" ]; then + waldir="${input}" + elif [ -f "${input}" ]; then + case "${input}" in + *.jpg|*.JPG|*.jpeg|*.JPEG|*.png|*.PNG) image="${input}" ;; + *) err "Unsupported file type" ;; + esac + else + err "Couldn't read given file" + fi fi -if [ -n "${waldir}" ]; then - image=$(find "${waldir}" -iregex '.*.\(jpg\|jpeg\|png\)' 2>/dev/null \ - | shuf -n 1 ) +if [ -d "$waldir" ]; then + image=$( + find "$waldir" \( -name '*.jpg' -o -name '*.jpeg' -o -name '*.png' \) 2>/dev/null | + awk 'BEGIN{srand()} {a[NR]=$0} END{if(NR>0) print a[int(rand()*NR)+1]}' + ) fi [ -z "${image}" ] && err "No image file found" -mkdir -p "$(dirname "${SYMLINK}")" && \ - ln -sf "${image}" "${SYMLINK}" && \ - run "xwallpaper --zoom ${image}" "${image}" +mkdir -p "$(dirname "${SYMLINK}")" && ln -sf "${image}" "${SYMLINK}" +wallpaper_handle set "${image}" && echo "${image}" |
