From f19f5df73ac0fdc3efa14649c4b646bcc4de84f4 Mon Sep 17 00:00:00 2001 From: Ryan Kavanagh Date: Thu, 21 Aug 2025 13:21:45 -0400 Subject: Move ~/bin to ~/.local/bin --- .chezmoiremove | 1 + bin/executable_Internet.m3u.sh | 40 --- bin/executable_copyright.awk | 122 ------- bin/executable_do_blue.sh | 2 - bin/executable_do_dac.sh | 19 - bin/executable_do_speakers.sh | 13 - bin/executable_icd | 112 ------ bin/executable_lbdb-fetchaddr-wrapper | 7 - bin/executable_lfoot | 3 - bin/executable_mailx-alias | 13 - bin/executable_mice.sh | 25 -- bin/executable_mpd_only.sh | 7 - bin/executable_mpd_others.sh | 10 - bin/executable_mutt-fetchbug | 161 --------- bin/executable_mutt_bgrun | 115 ------ bin/executable_mutt_oauth2.py | 443 ------------------------ bin/executable_ptmp | 50 --- bin/executable_startaudio | 3 - bin/executable_swaybg-random | 4 - bin/executable_tmcg | 29 -- bin/executable_wd-bak | 14 - bin/executable_wd-mount | 21 -- bin/executable_wd-umount | 24 -- bin/executable_wofi-window-switcher | 12 - dot_config/environment.d/01_PATH.conf | 2 +- dot_config/msmtp/config | 2 +- dot_config/systemd/user/swaybg-random.service | 2 +- dot_local/bin/executable_Internet.m3u.sh | 40 +++ dot_local/bin/executable_copyright.awk | 122 +++++++ dot_local/bin/executable_do_blue.sh | 2 + dot_local/bin/executable_do_dac.sh | 19 + dot_local/bin/executable_do_speakers.sh | 13 + dot_local/bin/executable_icd | 112 ++++++ dot_local/bin/executable_lbdb-fetchaddr-wrapper | 7 + dot_local/bin/executable_lfoot | 3 + dot_local/bin/executable_mailx-alias | 13 + dot_local/bin/executable_mice.sh | 25 ++ dot_local/bin/executable_mpd_only.sh | 7 + dot_local/bin/executable_mpd_others.sh | 10 + dot_local/bin/executable_mutt-fetchbug | 161 +++++++++ dot_local/bin/executable_mutt_bgrun | 115 ++++++ dot_local/bin/executable_mutt_oauth2.py | 443 ++++++++++++++++++++++++ dot_local/bin/executable_ptmp | 50 +++ dot_local/bin/executable_startaudio | 3 + dot_local/bin/executable_swaybg-random | 4 + dot_local/bin/executable_tmcg | 29 ++ dot_local/bin/executable_wd-bak | 14 + dot_local/bin/executable_wd-mount | 21 ++ dot_local/bin/executable_wd-umount | 24 ++ dot_local/bin/executable_wofi-window-switcher | 12 + 50 files changed, 1253 insertions(+), 1252 deletions(-) delete mode 100644 bin/executable_Internet.m3u.sh delete mode 100755 bin/executable_copyright.awk delete mode 100755 bin/executable_do_blue.sh delete mode 100755 bin/executable_do_dac.sh delete mode 100755 bin/executable_do_speakers.sh delete mode 100755 bin/executable_icd delete mode 100755 bin/executable_lbdb-fetchaddr-wrapper delete mode 100644 bin/executable_lfoot delete mode 100755 bin/executable_mailx-alias delete mode 100755 bin/executable_mice.sh delete mode 100755 bin/executable_mpd_only.sh delete mode 100755 bin/executable_mpd_others.sh delete mode 100755 bin/executable_mutt-fetchbug delete mode 100755 bin/executable_mutt_bgrun delete mode 100644 bin/executable_mutt_oauth2.py delete mode 100755 bin/executable_ptmp delete mode 100755 bin/executable_startaudio delete mode 100644 bin/executable_swaybg-random delete mode 100755 bin/executable_tmcg delete mode 100755 bin/executable_wd-bak delete mode 100644 bin/executable_wd-mount delete mode 100644 bin/executable_wd-umount delete mode 100644 bin/executable_wofi-window-switcher create mode 100644 dot_local/bin/executable_Internet.m3u.sh create mode 100755 dot_local/bin/executable_copyright.awk create mode 100755 dot_local/bin/executable_do_blue.sh create mode 100755 dot_local/bin/executable_do_dac.sh create mode 100755 dot_local/bin/executable_do_speakers.sh create mode 100755 dot_local/bin/executable_icd create mode 100755 dot_local/bin/executable_lbdb-fetchaddr-wrapper create mode 100644 dot_local/bin/executable_lfoot create mode 100755 dot_local/bin/executable_mailx-alias create mode 100755 dot_local/bin/executable_mice.sh create mode 100755 dot_local/bin/executable_mpd_only.sh create mode 100755 dot_local/bin/executable_mpd_others.sh create mode 100755 dot_local/bin/executable_mutt-fetchbug create mode 100755 dot_local/bin/executable_mutt_bgrun create mode 100644 dot_local/bin/executable_mutt_oauth2.py create mode 100755 dot_local/bin/executable_ptmp create mode 100755 dot_local/bin/executable_startaudio create mode 100644 dot_local/bin/executable_swaybg-random create mode 100755 dot_local/bin/executable_tmcg create mode 100755 dot_local/bin/executable_wd-bak create mode 100644 dot_local/bin/executable_wd-mount create mode 100644 dot_local/bin/executable_wd-umount create mode 100644 dot_local/bin/executable_wofi-window-switcher diff --git a/.chezmoiremove b/.chezmoiremove index 261612e..9e6654f 100644 --- a/.chezmoiremove +++ b/.chezmoiremove @@ -15,6 +15,7 @@ bin/mutt .mbsyncrc .xkb afs +bin {{- if eq .chezmoi.os "linux" }} diff --git a/bin/executable_Internet.m3u.sh b/bin/executable_Internet.m3u.sh deleted file mode 100644 index 62d83d0..0000000 --- a/bin/executable_Internet.m3u.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -# -# Updates the internet radio playlists for MPD -# Best run from a cronjob - -BASE=/var/lib/mpd/playlists.radio/ - -playlist() { - cat< "${BASE}/radio-$1.m3u" -#EXTM3U -#EXTINF:-1,$2 -$3 -EOF -} - -getstream() { - curl -s "$1" | grep '^File1=' | sed -e 's/File1=//g' -} - -playlist "1920s" "1920s Radio Network" "$(getstream 'http://kara.fast-serv.com:8398/listen.pls')" -# playlist "CFSF-FM" "CFSF-FM 99.3 (Sturgeon Falls)" 'http://listenlive.vistaradio.ca/CFSF' -# playlist "CHYK-FM" "CHYK-FM 104.1 (Timmins)" 'http://rubix.wavestreamer.com:8015/stream/1/' -playlist "CINN-FM" "CINN-FM 99.1 (Hearst)" 'http://stream2.statsradio.com:8050/stream' -# playlist "CJFO-FM" "CJFO-FM 94.5 (Ottawa)" 'http://stream03.ustream.ca:8000/cjfofm128.mp3' -playlist "CKGN-FM" "CKGN-FM 89.7 (Kapuskasing)" 'http://stream03.ustream.ca:80/ckgn128.mp3' -playlist "WYEP" "WYEP 91.3 (Pittsburgh)" 'https://ais-sa3.cdnstream1.com/2557_128.mp3' -playlist "WZUM" "WZUM 88.1 (Pittsburgh)" 'http://pubmusic.streamguys1.com/wzum-aac' -playlist "Dismuke" "Radio Dismuke" "$(getstream 'https://early1900s.org/radiodismuke/radiodismuke.pls')" -playlist "russhit" "99.6 Радио Русский Хит" "$(curl -s http://ruhit.fm/player.htm | grep ruhit_64 | sed -e 's/.*="//g;s/".*//g')" - -# http://colombiacrossover.com/ -playlist "salsa.dura" "Colombia Salsa Dura" "$(getstream 'http://64.37.50.226:8054/listen.pls?sid=1')" - -# http://www.tenientiko.com/ -playlist "salsa.catedral" "La Catedral de la Salsa" "$(getstream 'http://176.31.120.166:4450/listen.pls?sid=1')" - -# http://www.rockolapegassera.com -playlist "cumbia.rockola" "Rockola Pegassera 107.9" "$(getstream 'http://54.39.19.215:8004/listen.pls?sid=1')" - -playlist "salsa.metro" "El Metro Salsero" 'http://s5.voscast.com:7516/stream' diff --git a/bin/executable_copyright.awk b/bin/executable_copyright.awk deleted file mode 100755 index 371a9c2..0000000 --- a/bin/executable_copyright.awk +++ /dev/null @@ -1,122 +0,0 @@ -#!/usr/bin/gawk -f -# Copyright (C) 2013 Ryan Kavanagh -# Given a series of lines in the format -# Copyright (c) NNNN, MMMM-MMMM, ..., NNNN John Smith -# group years and emails by person. - -{ - match($0, /.*Copyright.*[0-9][,]? +/); - DATE_LENGTH = RLENGTH; - match($0, /<.*>/); - EMAIL_START = RSTART; - if (RLENGTH != -1) { - NAME = substr($0, DATE_LENGTH + 1, EMAIL_START - DATE_LENGTH - 2); - EMAIL = substr($0, EMAIL_START); - } else { - # No email on this line - NAME = substr($0, DATE_LENGTH + 1); - } - match($0, /.*Copyright +\([cC]\) +/); - DATE_START = RLENGTH + 1; - YEARS = substr($0, DATE_START, DATE_LENGTH - DATE_START); - gsub(/, +/, " ", YEARS); - gsub(/,/, " ", YEARS); - people_years[NAME] = people_years[NAME] " " YEARS; - if (EMAIL_LENGTH != -1) { - email_pattern = "/.*" EMAIL ".*/"; - if (!(NAME in people_emails)) { - people_emails[NAME] = EMAIL; - } else if (!match(people_emails[NAME], EMAIL)) { - people_emails[NAME] = people_emails[NAME] "," EMAIL; - } - } -} END { - for (person in people_years) { - delete years_array; - split(people_years[person], years_array); - # Split any hyphenated years; - for (year in years_array) { - if (years_array[year] ~ /[0-9]+-[0-9]+/) { - delete split_year; - split(years_array[year], split_year, /-/); - years_array[year] = split_year[1]; - if (split_year[1] != split_year[2]) { - # Make sure it isn't some crappy input like 2012-2012 - for (j = 1; j <= split_year[2] - split_year[1]; j++) { - years_array[length(years_array) + 1] = \ - years_array[year] + j; - } - } - } - } - # Sort the years - asort(years_array); - # Delete any duplicates: - for (i = 1; i <= length(years_array); i++) { - if (i > 1 && years_array[i-1] == years_array[i]) { - # Delete years_array[i-1] instead of years_array[i] so that we - # can still check the next year with ease - delete years_array[i-1]; - } - } - # Final sort - asort(years_array); - # Remove duplicates and generate year string - year_string = ""; - # Force AWK to access the years in order - added_hyphen = 0; - for (i = 1; i <= length(years_array); i++) { - if (i > 1) { - if (years_array[i - 1] != years_array[i]) { - # added_hyphen tracks if the last character in the string is - # a hyphen - if ((!added_hyphen) && (years_array[i - 1] == years_array[i] - 1)) { - # year_string isn't terminated by a hyphen, and the year - # at i-1 is one less than the current one - year_string = year_string "-"; - added_hyphen = 1; - } else if (added_hyphen && (years_array[i - 1] != years_array[i] - 1)) { - # The string is terminated by a hyphen, but the current - # year does not immediately follow the preceeding - # one - year_string = year_string years_array[i-1] ", " years_array[i]; - added_hyphen = 0; - } else if (!added_hyphen) { - year_string = year_string ", " years_array[i]; - } - } - } else { - year_string = years_array[i]; - } - } - # We've added a hyphen, but run out of years to check, terminate it - if (added_hyphen) { - year_string = year_string years_array[length(years_array)]; - } - final_line[years_array[length(years_array)]][length(years_array)][person] = \ - "Copyright (C) " year_string "\t" person " " people_emails[person]; - } - # We can't sort the years indices with asorti because we want a numerical, - # not lexicographic sort of the indices. - j = 0; - delete years_sorted; - for (i in final_line) years_sorted[j++] = i+0; - n_years_entries = asort(years_sorted); - # And output the lines with the most recent contributor first - for (y = n_years_entries; y >= 1; y--) { - # Sort the contributors with most recent contribution in year - # by_year[y] by number of years contributed: - j = 0; - delete contributions_sorted; - for (i in final_line[years_sorted[y]]) contributions_sorted[j++] = i+0; - n_contrib_entries = asort(contributions_sorted); - for (c = n_contrib_entries; c >= 1; c--) { - # Finally, sort by contributor name - asorti(final_line[years_sorted[y]][contributions_sorted[c]], by_person); - # And output the lines in alphabetical order by person name - for (n = 1; n <= length(by_person); n++) { - print final_line[years_sorted[y]][contributions_sorted[c]][by_person[n]]; - } - } - } -} diff --git a/bin/executable_do_blue.sh b/bin/executable_do_blue.sh deleted file mode 100755 index cd79e50..0000000 --- a/bin/executable_do_blue.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -bluetoothctl -- connect CD:0D:69:69:9A:1B diff --git a/bin/executable_do_dac.sh b/bin/executable_do_dac.sh deleted file mode 100755 index 7ae913e..0000000 --- a/bin/executable_do_dac.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -USB_CARD="alsa_card.usb-FiiO_DigiHug_USB_Audio-01" -USB_SINK="alsa_output.usb-FiiO_DigiHug_USB_Audio-01.iec958-stereo" -SPEAKERS="alsa_output.pci-0000_00_1b.0.analog-stereo" - -pacmd set-sink-mute "${SPEAKERS}" 1 -pacmd set-card-profile "${USB_CARD}" output:iec958-stereo -pacmd set-sink-mute "${USB_SINK}" 0 - -if pacmd list-modules | grep module-ladspa-sink; then - pacmd unload-module module-ladspa-sink -fi -pacmd load-module module-ladspa-sink sink_name=binaural sink_master="${USB_SINK}" plugin=bs2b label=bs2b control=700,4.5 - -for s in $(pacmd list-sink-inputs | awk '$1 == "index:" {print $2}') -do - pacmd move-sink-input $s "${USB_SINK}" >/dev/null 2>&1 -done diff --git a/bin/executable_do_speakers.sh b/bin/executable_do_speakers.sh deleted file mode 100755 index 84b82e1..0000000 --- a/bin/executable_do_speakers.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -USB_CARD="alsa_card.usb-FiiO_DigiHug_USB_Audio-01" -USB_SINK="alsa_output.usb-FiiO_DigiHug_USB_Audio-01.iec958-stereo" -SPEAKERS="alsa_output.pci-0000_00_1b.0.analog-stereo" - -pacmd set-sink-mute "${USB_SINK}" 1 -pacmd set-sink-mute "${SPEAKERS}" 0 - -for s in $(pacmd list-sink-inputs | awk '$1 == "index:" {print $2}') -do - pacmd move-sink-input $s "${SPEAKERS}" >/dev/null 2>&1 -done diff --git a/bin/executable_icd b/bin/executable_icd deleted file mode 100755 index 367b87f..0000000 --- a/bin/executable_icd +++ /dev/null @@ -1,112 +0,0 @@ -#!/bin/sh - -XKB_DIR=${HOME}/.xkb -[ -d ${XKB_DIR}/keymap ] || mkdir -p ${XKB_DIR}/keymap - -GLOBAL_OPTIONS="\ - -I${XKB_DIR} \ - -layout icd,ru \ - -variant icd, \ - -option terminate:ctrl_alt_bksp \ - -option nbsp:level3n \ - -option lalt_meta:lalt_meta \ - -option grp:shifts_toggle" - -LAPTOP_OPTIONS="\ - ${GLOBAL_OPTIONS} \ - -option lv3:ralt_switch_multikey" - -KIN_OPTIONS="\ - ${GLOBAL_OPTIONS} \ - -option lv3:switch \ - -option caps:swapescape" - -SUN_OPTIONS="\ - ${GLOBAL_OPTIONS} \ - -geometry sun(type6unix) \ - -option caps:escape \ - -option lv3:menu_switch \ - -option myswap:switch_lalt_lsuper" - -ERG_OPTIONS="\ - ${GLOBAL_OPTIONS} \ - -option lv3:switch \ - -option caps:escape" - - -case `uname` in - OpenBSD) - LAPTOP_ID=$(xinput | grep "/dev/wskbd" | sed -e 's/.*id=\([0-9]\+\).*/\1/g') - ;; - Linux) - LAPTOP_ID=$(xinput | grep "AT Translated Set 2 keyboard" | sed -e 's/.*id=\([0-9]\+\).*/\1/g') - KIN_USB_ID=$(lsusb | grep -i "Kinesis Advantage Pro" | awk '{ print $6 }') - ERG_USB_ID=$(lsusb | grep -i "feed:1307" | awk '{ print $6 }') - SUN_USB_ID=$(lsusb | grep -i "Sun Microsystems, Inc. Type 6 Keyboard" | awk '{ print $6 }') - ;; - *) - ;; -esac - -echo "Setting up laptop" -setxkbmap ${LAPTOP_OPTIONS} -device ${LAPTOP_ID} -print > ${XKB_DIR}/keymap/icd.laptop -# xkbcomp -I${HOME}/.xkb -i ${LAPTOP_ID} -synch \ -xkbcomp -I${HOME}/.xkb -synch \ - ${HOME}/.xkb/keymap/icd.laptop $DISPLAY # 2> /dev/null - -if [ "x${KIN_USB_ID}" != "x" ]; then - echo "Setting up Kinesis" - KIN_XINPUT_ID=$(xinput | grep ${KIN_USB_ID} | sed -e 's/.*id=\([0-9]\+\).*/\1/g') - for XID in $KIN_XINPUT_ID; do - echo $XID - setxkbmap \ - -I${XKB_DIR} \ - -device ${XID} \ - ${KIN_OPTIONS} \ - -print | sed -e 's@+ctrl(nocaps)@@g;s@bksp)@bksp)+lalt_meta(lalt_meta)@g' > ${HOME}/.xkb/keymap/icd.kin - xkbcomp -I${HOME}/.xkb -i ${XID} -synch \ - ${HOME}/.xkb/keymap/icd.kin ${DISPLAY} # 2> /dev/null - done - xkbcomp -I${HOME}/.xkb -synch \ - ${HOME}/.xkb/keymap/icd.kin ${DISPLAY} # 2> /dev/null - xmodmap -e "remove mod1 = Alt_R" - xmodmap -e "add mod4 = Alt_R" -fi - -if [ "x${SUN_USB_ID}" != "x" ]; then - echo "Setting up Sun Type 6" - SUN_XINPUT_ID=$(xinput | grep ${SUN_USB_ID} | sed -e 's/.*id=\([0-9]\+\).*/\1/g') - echo "ID: ${SUN_XINPUT_ID}" - for XID in $SUN_XINPUT_ID; do - echo $XID - setxkbmap \ - -I${XKB_DIR} \ - -device ${XID} \ - ${SUN_OPTIONS} \ - -print | sed -e '/xkb_keycodes/s/"[[:space:]]/+sunt6fix&/' > ${HOME}/.xkb/keymap/icd.sun - xkbcomp -I${HOME}/.xkb -i ${XID} -synch \ - ${HOME}/.xkb/keymap/icd.sun ${DISPLAY} # 2> /dev/null - done -fi - -echo ${ERG_USB_ID} -if [ "x${ERG_USB_ID}" != "x" ]; then - echo "Setting up ergodox" - ERG_XINPUT_ID=$(xinput | grep "ErgoDox EZ" | grep keyboard | sed -e 's/.*id=\([0-9]\+\).*/\1/g') - echo "ID: ${ERG_XINPUT_ID}" - for XID in $ERG_XINPUT_ID; do - echo $XID - setxkbmap \ - -I${XKB_DIR} \ - -device ${XID} \ - ${ERG_OPTIONS} \ - -print > ${HOME}/.xkb/keymap/icd.erg - # -print | sed -e 's@+group(shifts_toggle)@+ctrl(nocaps)&@g' > ${HOME}/.xkb/keymap/icd.erg - # xkbcomp -I${HOME}/.xkb -i ${XID} -synch \ - xkbcomp -I${HOME}/.xkb -synch \ - ${HOME}/.xkb/keymap/icd.erg ${DISPLAY} # 2> /dev/null - done -fi - - -echo icd > ${HOME}/.xmonad/layout diff --git a/bin/executable_lbdb-fetchaddr-wrapper b/bin/executable_lbdb-fetchaddr-wrapper deleted file mode 100755 index bb1270a..0000000 --- a/bin/executable_lbdb-fetchaddr-wrapper +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -if command -v lbdb-fetchaddr > /dev/null; then - { tee /dev/fd/3 | lbdb-fetchaddr >&2; } 3>&1 -else - cat -fi diff --git a/bin/executable_lfoot b/bin/executable_lfoot deleted file mode 100644 index 5522085..0000000 --- a/bin/executable_lfoot +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -foot -c ${HOME}/.config/foot/lfoot.ini diff --git a/bin/executable_mailx-alias b/bin/executable_mailx-alias deleted file mode 100755 index c1d961a..0000000 --- a/bin/executable_mailx-alias +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -MUTT_ALIAS=${HOME}/.mutt/alias.rc -MAILX_ALIAS=${HOME}/.mailx-aliases.rc - -awk '{ - NAME=""; - for (i = 3; i < NF; i++) { - NAME=NAME " " $i; - }; - NAME = substr(NAME, 2); - print "alias", $2, "\"" $NF, "(" NAME ")\""; -}' $MUTT_ALIAS > $MAILX_ALIAS diff --git a/bin/executable_mice.sh b/bin/executable_mice.sh deleted file mode 100755 index 794f86f..0000000 --- a/bin/executable_mice.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -# Synaptics: -synclient HorizTwoFingerScroll=0 || true -synclient HorizEdgeScroll=1 || true -# Enable circular scrolling with top edge activating -synclient CircularScrolling=1 || true -synclient CircScrollTrigger=1 || true -# One finger is left click -synclient TapButton1=1 || true -# Two is right click -synclient TapButton2=3 || true -# Three is middle click -synclient TapButton3=2 || true -# Enable coasting -synclient CoastingSpeed=5 -synclient CoastingFriction=30 - -trackball=$(xinput | grep "Kensington Expert Wireless TB" | grep pointer | sed -e 's/.*id=//g;s/\s\+.*//g') -if [ "x${trackball}" != "x" ]; then - xinput set-button-map "${trackball}" 1 2 8 4 5 6 7 3 9 10 11 12 13 14 15 16 - xinput set-prop "${trackball}" "libinput Accel Speed" 0.25 -fi - - diff --git a/bin/executable_mpd_only.sh b/bin/executable_mpd_only.sh deleted file mode 100755 index 468c6a5..0000000 --- a/bin/executable_mpd_only.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -set -e - -systemctl --user stop pulseaudio.socket -mpc enable "DigiHug USB Audio" -mpc disable "My Pulse Output" diff --git a/bin/executable_mpd_others.sh b/bin/executable_mpd_others.sh deleted file mode 100755 index b27e11e..0000000 --- a/bin/executable_mpd_others.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -set -e - -systemctl --user start pulseaudio.socket -systemctl --user start pulseaudio.service -mpc disable "DigiHug USB Audio" -mpc enable "My Pulse Output" -pacmd load-module module-udev-detect -${HOME}/bin/do_dac.sh diff --git a/bin/executable_mutt-fetchbug b/bin/executable_mutt-fetchbug deleted file mode 100755 index 93ffc58..0000000 --- a/bin/executable_mutt-fetchbug +++ /dev/null @@ -1,161 +0,0 @@ -#!/usr/bin/perl -w -# -# mutt-fetchbug, extensively based off of -# mutt-notmuch - notmuch (of a) helper for Mutt -# -# Copyright: © 2011 Stefano Zacchiroli -# License: GNU General Public License (GPL), version 3 or above -# -# Differences between mutt-notmuch and mutt-fetchbug are -# Copyright: © 2012 Ryan Kavanagh -# License: GNU General Public License (GPL), version 3 or above -# -# See the bottom of this file for more documentation. -# A manpage can be obtained by running "pod2man mutt-fetchbug > mutt-fetchbug.1" - -use strict; -use warnings; - -use File::Path; -use Getopt::Long; -use Pod::Usage; - -# search($btsmbox, $query) -# Fetch bugs matching $query with bts; store results in $btsmbox -sub search($$) { - my ($btsmbox, $query) = @_; - - system("bts --cache-mode=mbox cache $query" - . " && ln -fs ~/.cache/devscripts/bts/$query.mbox $btsmbox"); -} - -sub search_action($$@) { - my ($interactive, $btsmbox, @params) = @_; - - if (! $interactive) { - fetch($btsmbox, join(' ', @params)); - } else { - my $query = ""; - my $done = 0; - while (! $done) { - print "bug number ('?' for man): "; - chomp($query = ); - if ($query eq "?") { - system("man bts"); - } elsif ($query eq "") { - $done = 1; # quit doing nothing - } else { - search($btsmbox, $query); - $done = 1; - } - } - } -} - -sub die_usage() { - my %podflags = ( "verbose" => 1, - "exitval" => 2 ); - pod2usage(%podflags); -} - -sub main() { - my $btsmbox = "$ENV{HOME}/.cache/mutt_btsresults"; - my $interactive = 0; - my $help_needed = 0; - - my $getopt = GetOptions( - "h|help" => \$help_needed, - "o|output-mbox=s" => \$btsmbox, - "p|prompt" => \$interactive); - if (! $getopt || $#ARGV < 0) { die_usage() }; - my ($action, @params) = ($ARGV[0], @ARGV[1..$#ARGV]); - - if ($help_needed) { - die_usage(); - } elsif ($action eq "search" && $#ARGV == 0 && ! $interactive) { - print STDERR "Error: no search term provided\n\n"; - die_usage(); - } elsif ($action eq "search") { - search_action($interactive, $btsmbox, @params); - } else { - die_usage(); - } -} - -main(); - -__END__ - -=head1 NAME - -mutt-fetchbug - 'bts show' frontend for Mutt - -=head1 SYNOPSIS - -=over - -=item B [I