&2
28 | }
29 |
30 | die() {
31 | exit 1
32 | }
33 |
34 | has() {
35 | local verbose=0
36 | if [[ $1 = '-v' ]]; then
37 | verbose=1
38 | shift
39 | fi
40 | for c; do c="${c%% *}"
41 | if ! command -v "$c" &> /dev/null; then
42 | (( "$verbose" > 0 )) && err "$c not found"
43 | return 1
44 | fi
45 | done
46 | }
47 |
48 | select_from() {
49 | local cmd='command -v'
50 | for a; do
51 | case "$a" in
52 | -c)
53 | cmd="$2"
54 | shift 2
55 | ;;
56 | esac
57 | done
58 | for c; do
59 | if $cmd "${c%% *}" &> /dev/null; then
60 | echo "$c"
61 | return 0
62 | fi
63 | done
64 | return 1
65 | }
66 |
67 | fzf() {
68 | command fzf -e +s --multi --cycle --ansi \
69 | --bind='Ctrl-X:toggle-preview' \
70 | --no-hscroll --inline-info \
71 | --header='tab to select multiple packages, Ctrl-X for more info on a package' "$@"
72 | }
73 |
74 | install() {
75 | local pkgs count
76 | mapfile -t pkgs
77 | (( ${#pkgs} > 0 )) || exit
78 | count="${#pkgs[@]} package"
79 | (( ${#pkgs[@]} > 1 )) && count+='s'
80 | printf "installing %s: %s\n" "$count" "${pkgs[*]}"
81 | $1 "${pkgs[@]}" < /dev/tty
82 | }
83 |
84 | debian() {
85 | fzf --preview='apt-cache show {1}' \
86 | --query="$1" \
87 | < <(apt-cache search '.*' | sort |
88 | sed -u -r "s|^([^ ]+)|${c_green}\1${c_reset}|") |
89 | cut -d' ' -f1 |
90 | install "sudo $(select_from 'apt' 'aptitude' 'apt-get') install"
91 | }
92 |
93 | arch() {
94 | local search packages
95 | search='pacman'
96 | [[ -n "$1" ]] && search=$(select_from 'pacaur' 'trizen' 'yaourt' 'packer' 'apacman' 'pacman')
97 | packages=$(fzf --preview="$search -Si {2}" \
98 | < <( $search -Ss "$1" |
99 | gawk '{
100 | getline descr;
101 | sub(/ */,"", descr);
102 | repo = blue "[" gensub(/\/.*/, "", 1) "]" reset;
103 | name = green gensub(/.*\//, "", 1, $1) reset;
104 | info = gensub(/[^ ]* /, "", 1);
105 | print repo, name, info, descr;
106 | }' blue="$c_blue" green="$c_green" reset="$c_reset"
107 | ) | cut -d' ' -f2)
108 | [[ "$search" = "pacman" ]] && search="sudo pacman"
109 | install "$search -S" <<< "$packages"
110 | }
111 |
112 | void() {
113 | local package_list packagename='{ sub(/-[^\-]*$/, "", $2); print $2 }'
114 | package_list=$(xbps-query -Rs '' | sort)
115 | fzf --preview="p=\$(awk \"$packagename\" <<< {}); xbps-query -Rx \$p" \
116 | --query="$1" <<< "$package_list" |
117 | awk "$packagename" |
118 | install 'xbps-install -S'
119 | }
120 |
121 | fedora() {
122 | fzf --query="$*" --preview='p={}; p="${p%% *}"; dnf -q info "${p%.*}"' \
123 | < <(dnf -qC repoquery --qf "${c_green}%{name} ${c_reset} - %{summary}" \*) |
124 | awk '{ package=$1; sub(/\.\S+/, "", package); print package }' |
125 | install 'sudo dnf install'
126 | }
127 |
128 | while true; do
129 | case "$1" in
130 | -h|--help) usage; exit ;;
131 | -p|--preview) preview_pos="$2"; shift 2 ;;
132 | *) break
133 | esac
134 | done
135 |
136 | has -v fzf gawk || die
137 |
138 | request="$*"
139 |
140 | if [[ -r /etc/os-release ]]; then
141 | distro=$(awk -F'=' '"NAME" == $1 { gsub("\"", "", $2); print tolower($2); }' /etc/os-release)
142 | distro="${distro%% *}"
143 | else
144 | distro="$(uname -o)"
145 | fi
146 |
147 | case "$distro" in
148 | debian|ubuntu|Android) debian "$request" ;;
149 | arch) arch "$request" ;;
150 | manjaro) arch "$request" ;;
151 | void) void "$request" ;;
152 | fedora) fedora "$request" ;;
153 | *) die 'unknown distro :(' ;;
154 | esac
155 |
156 | # TODO: homebrew: brew desc -s
157 | # sample output: https://pastebin.com/raw/3frRf6C7
158 |
--------------------------------------------------------------------------------
/dmenu/cabl:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Dependencies are xclip and xorg-xprop.
3 | # qrencode required for qrcode generation.
4 |
5 | [ -z "$LAUNCER" ] && LAUNCER="dmenu"
6 | [ -z "$OPENER" ] && OPENER="xdg-open"
7 | while getopts cs: f
8 | do
9 | case $f in
10 | c)
11 | prim="$(xclip -o)"
12 | if [ -z "${prim}" ]; then
13 | notify-send "no selection in clipboard"
14 | exit 1
15 | fi
16 | ;;
17 | s)
18 | src=$OPTARG
19 | ;;
20 | \?)
21 | printf 'Invalid option: -%s\n' "${f}" && exit 1
22 | ;;
23 | esac
24 | done
25 | shift $(( OPTIND - 1))
26 |
27 | # Custom opener when called from shell
28 | shellopener(){
29 | open $*
30 | exit 1
31 | }
32 |
33 | fallbackopen() {
34 | case ${prim} in
35 | *.xopp)
36 | exec xournalpp "${prim}"
37 | ;;
38 | *)
39 | exec "$OPENER" "${prim}"
40 | ;;
41 | esac
42 |
43 |
44 | }
45 |
46 | istext(){
47 | case $src in
48 | shell)
49 | case "$*" in
50 | *\.1)
51 | exec man "$*"
52 | ;;
53 | *)
54 | exec "${EDITOR:-vi}" "$*"
55 | ;;
56 | esac
57 | ;;
58 | vim)
59 | nvr -o "$*" --nostart && exit
60 | ;;
61 | *)
62 | fallbackopen "$*"
63 | ;;
64 | esac
65 | fallbackopen "$*"
66 | }
67 |
68 |
69 | isfile() {
70 | case $(file --mime-type "$*" -b) in
71 | # follow symlinks
72 | inode/symlink) isfile "$(readlink "$*")" && exit;;
73 | # open text files with sc
74 | text/*) istext "$*";;
75 | *) for f in "$@"; do fallbackopen "$*" > /dev/null 2> /dev/null & done && exit 0;;
76 | esac
77 | }
78 |
79 | isdir() {
80 | cd "$*" && exec "$TERMINAL" && exit 0
81 | fallbackopen "$*"
82 | }
83 |
84 | [ -z "${prim}" ] && prim="$*"
85 | [ -z "${prim}" ] && exit
86 | PID=$(xprop -id "$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')" | grep -m 1 PID | cut -d " " -f 3)
87 | PID=$(echo "$(pstree -lpA "${PID}" | tail -n 1)" | awk -F'---' '{print $NF}' | sed -re 's/[^0-9]//g')
88 | cd "$(readlink /proc/"${PID}"/cwd)" || exit
89 |
90 | # FILE
91 | prim=$(echo "${prim}" | sed 's/file://g') # Remove file url
92 | [ -f "${prim}" ] && isfile "${prim}" && exit 1
93 |
94 | browse() { exec "${BROWSER}" "${prim}" ; }
95 | email() { xdg-email "${prim}" && exit; }
96 | vimplug() { exec "${BROWSER}" "https://github.com/$(echo "${prim}" | cut -d\' -f2)"; }
97 | errormsg() { exec "${TERMINAL}" -e "${EDITOR:-vi}" "$(echo "${prim}" | cut -d: -f1)" "+$(echo "${prim}" | cut -d: -f2)" ; }
98 | date() {
99 | exec "${BROWSER}" "https://calendar.google.com/calendar/r/day/$(echo "${prim}" |
100 | awk -F '[- ]' '{$1=$1}1 {printf "%s/%s/%s", $1, $2, $3}' | tr -d '<')"
101 | }
102 |
103 | # DIRECTORY
104 | [ -d "$prim" ] && isdir "${prim}" && exit 1
105 |
106 | # ONLY ONE LINE
107 | if [ "$(echo "${prim}" | wc -l )" -eq 1 ] ; then
108 | # URL
109 | echo "${prim}" | grep "^\s*https\?.*\.[A-Za-z]\+.*" > /dev/null && browse
110 | # EMAIL
111 | echo "${prim}" | grep "[A-Za-z0-9._%+-]\+@[A-Za-z0-9.-]\+\.[A-Za-z]\{2,6\}\$" > /dev/null && email
112 | # VIM PLUGIN
113 | echo "${prim}" | grep ".*Plug.*'.*/.*'.*" > /dev/null && vimplug
114 | # ERROR MESSAGE
115 | echo "${prim}" | cut -d: -f1 | xargs -r test -f &&
116 | echo "${prim}" | grep -E '^[A-Za-z/\.-]+:[0-9]+' > /dev/null && errormsg
117 | # DATE https://calendar.google.com/calendar/r/day/
118 | echo "${prim}" | grep '\s*<\?[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\} [a-zA-Z]\{3\} \?\([0-9]\{2\}:[0-9]\{2\}\)\?>\?\s*' > /dev/null && date
119 | fi
120 |
121 | # BEGIN OPTIONS
122 | OPTIONS="
123 | search
124 | qrcode
125 | maps
126 | read"
127 |
128 | search() { "${BROWSER}" "https://duckduckgo.com/?q=$*"; }
129 | qrcode() { qrencode "$*" -s 10 -o /tmp/qr.png && "$OPENER" /tmp/qr.png; }
130 | maps() { "${BROWSER}" "https://maps.google.com/?q=$*"; }
131 | dhandler() { dmenuhandler "$@"; }
132 | manual() { man -Tpdf "${prim}" | ${READER} -; }
133 |
134 | # READ ALOUD
135 | read() {
136 | tts.sh "$1"
137 | # killall aplay
138 | # pico2wave -w=/tmp/test.wav -- "$1"
139 | # picospeaker "$*"
140 | # aplay /tmp/test.wav -D 'pulse'
141 | # aplay /tmp/test.wav
142 | # rm /tmp/test.wav
143 | }
144 |
145 |
146 | # MAYBE A URL
147 | echo "${prim}" | grep "^.*\.[A-Za-z]\+.*" > /dev/null && OPTIONS="${OPTIONS}\ndhandler"
148 |
149 | # check if single word
150 | if [ "$(echo "${prim}" | wc -w)" -eq 1 ]; then
151 | # if manpage exists
152 | man -w "${prim}" > /dev/null && OPTIONS="${OPTIONS}\nmanual"
153 | fi
154 |
155 | prompt="Plumb \"$(echo "${prim}" | awk ' NR==1' | cut -c -18)\" to?"
156 |
157 | func="$(printf "$OPTIONS" | awk 'NR>1' | ${LAUNCER} -p "${prompt}" -i -l 15)"
158 |
159 | [ -z "${func}" ] || "${func}" "${prim}"
160 | #vim:ft=sh
161 |
--------------------------------------------------------------------------------
/tools/psave.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/sh
2 |
3 | ######################################################################
4 | # @author : Gavin Jaeger-Freeborn (gavinfreeborn@gmail.com)
5 | # @file : psave.sh
6 | # @created : Thu 05 Dec 2019 01:03:47 PM MST
7 | #
8 | # @description : This is a simple script used for managing power.
9 | # Simply set this as a cronjob (i have it run every 15
10 | # minutes). This script is specific to my thinkpad x200, I
11 | # tried to remove some of the stuff specific to me and left a
12 | # label where it used to be.
13 | #
14 | # @resources : If you want to learn more about how this script works and
15 | # other optimizations checkout these resources.
16 | # https://wiki.archlinux.org/index.php/CPU_frequency_scaling
17 | # https://wiki.archlinux.org/index.php/Power_management
18 | #
19 | # @WARNING : This script may conflict with other power managers on your
20 | # system such as tlp. This Script is very specific to my
21 | # machine so you will probably have to make some adjustments.
22 | ######################################################################
23 |
24 | # manage power to usb ports
25 |
26 | wifiman(){
27 | # Check for wifi and determines if it should start syncthing
28 | if ping -q -c 1 8.8.8.8; then
29 | syncthing -no-browser 2>&1 >/dev/null | xargs notify-send
30 | WIFI=$(nmcli connection show --active | sed '1d' | awk '{print $1}')
31 |
32 | # Only kill kdeconnect when using wifi that doesn't support it
33 | case ${WIFI} in
34 | Uvic )
35 | killall kdeconnectd ;;
36 | ShawOpen )
37 | killall kdeconnectd ;;
38 | *)
39 | # If on any other wifi start kdeconnect
40 | # Since kdeconnect isnt working comment it out
41 | # kdeconnect-cli -l;;
42 | esac
43 | else
44 | # If there is no wifi kill syncthing and kdeconnect
45 | killall syncthing
46 | # killall kdeconnectd
47 | fi
48 | }
49 |
50 | # This adjusts the maximum clock of the cpu depending on the current battery
51 | # percentage as well as if it is charging. If you have a more modern CPU I
52 | # highly recommend you use spcpugov instead. the numbers used for
53 | # scaling_max_freq should be adjusted based on the options available for your
54 | # computer. to find these stats use check the
55 | # /sys/devices/system/cpu/cpu1/cpufreq/scaling_available_frequencies.
56 | # double check that the BAT# is correct for your computer
57 | cpugov(){
58 | full=$(cat /sys/class/power_supply/BAT0/energy_full)
59 | now=$(cat /sys/class/power_supply/BAT0/energy_now)
60 | state=$(cat /sys/class/power_supply/BAT0/status)
61 | [ "${state}" = Charging ] && echo ondemand | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor && \
62 | echo 1867000 | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq && exit
63 | batt=$(echo "scale=2; 100*(${now}/${full})" | bc | cut -d"." -f1)
64 | [ "${batt}" -ge "80" ] && echo ondemand | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor && \
65 | echo 1867000 | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq && exit
66 | [ "${batt}" -ge "35" ] && echo ondemand | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor && \
67 | echo 1600000 | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq && exit
68 | echo powersave | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor && \
69 | echo 1867000 | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq && exit
70 | }
71 |
72 | # This version of cpugov is works on more modern computers since intel_pstate
73 | # is more efficient then cpufreq but is only available in 'core i' series cpus
74 | # double check that the BAT# is correct for your computer
75 | spcpugov(){
76 | full=$(cat /sys/class/power_supply/BAT1/energy_full)
77 | now=$(cat /sys/class/power_supply/BAT1/energy_now)
78 | state=$(cat /sys/class/power_supply/BAT1/status)
79 | [ "${state}" = Charging ] && echo 100 | sudo tee /sys/devices/system/cpu/intel_pstate/max_perf_pct && exit
80 | batt=$(echo "scale=2; 100*(${now}/${full})" | bc | cut -d"." -f1)
81 | [ "${batt}" -ge "80" ] && echo 80 | sudo tee /sys/devices/system/cpu/intel_pstate/max_perf_pct && exit
82 | [ "${batt}" -ge "35" ] && echo 50 | sudo tee /sys/devices/system/cpu/intel_pstate/max_perf_pct && exit
83 | echo 26 | sudo tee /sys/devices/system/cpu/intel_pstate/max_perf_pct && exit
84 | }
85 |
86 | # device=$(uname -n)
87 | wifiman "$1"
88 | # replace MODERN with the name of the system that should use spcpugov
89 | # [ "$device" = "MODERN" ] && spcpugov && exit
90 | # cpugov
91 |
92 | # vim: set tw=78 ts=2 et sw=2 sr:
93 |
--------------------------------------------------------------------------------
/tools/compiler:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # This script will compile or run another finishing operation on a document. I
4 | # have this script run via Vim.
5 | # # tex files: Compiles to pdf, including bibliography if necessary
6 | # md files: Compiles to pdf via pandoc
7 | # rmd files: Compiles via R Markdown
8 | # c files: Compiles via whatever compiler is set to cc. Usually gcc.
9 | # Use make if Makefile exists.
10 | # py files: runs via python command
11 | # go files: compiles and runs with "go run"
12 | # config.h files: (For suckless utils) recompiles and installs program.
13 | # all others: run `sent` to show a presentation
14 |
15 | file=$(readlink -f "$1")
16 | dir=$(dirname "$file")
17 | base="${file%.*}"
18 |
19 | cd "$dir" || exit
20 |
21 | Ifinstalled() {
22 | command -v "$1" >/dev/null || { notify-send "📦 $1 must be installed for this function." && exit 1; }
23 | }
24 |
25 | textype() {
26 | command="pdflatex"
27 | errorfmt="-file-line-error"
28 | # ( sed 5q "$file" | grep -i -q 'xelatex' ) && command="xelatex"
29 | secdir="$(dirname "$dir")"
30 | cd "$secdir"
31 | if [ -f "${secdir}/Notes.tex" ]; then
32 | echo "${secdir}/Notes.tex"
33 | $command $errorfmt --output-directory="$secdir" "${secdir}/Notes.tex"
34 | exit
35 | fi
36 | $command $errorfmt --output-directory="$dir" "$base"
37 | grep -i addbibresource "$file" >/dev/null &&
38 | biber --input-directory "$dir" "$base" &&
39 | $command $errorfmt --output-directory="$dir" "$base" &&
40 | $command $errorfmt --output-directory="$dir" "$base"
41 | }
42 |
43 | pandoccmd() {
44 | # Ifinstalled pdflatex && pandoc -V geometry:margin=4cm -f markdown-implicit_figures "$1" -o "${2}.pdf"
45 | Ifinstalled groff && pandoc "${1}" -t ms --pdf-engine-opt=-p -o "${2}.pdf"
46 | }
47 |
48 | pandocorg() { pandoccmd "$file" "$base"; }
49 |
50 | compilec() {
51 | if [ -f "${dir}/Makefile" ]; then
52 | make
53 | else
54 | clang "$file" -o "$base" && "$base"
55 | fi
56 | }
57 |
58 | neatroff_prefix='/opt/share/neatroff'
59 |
60 | case "$file" in
61 | *\.ms | *\.groff) preconv "$file" | groff -Tpdf -ktesp -ms >"$base".pdf ;;
62 | # *\.ms | *\.groff)
63 | # cat "$file"|
64 | # ${neatroff_prefix}/soin/soin |
65 | # ${neatroff_prefix}/troff/tbl/tbl |
66 | # ${neatroff_prefix}/troff/pic/pic |
67 | # ${neatroff_prefix}/neateqn/eqn |
68 | # ${neatroff_prefix}/neatroff/roff -men -mpost -mkeep -mfp |
69 | # ${neatroff_prefix}/neatpost/pdf > "$base".pdf &&
70 | # killall -s SIGHUP mupdf;;
71 | *\.sh) bash "$file" ;;
72 | *\.ps) ps2pdf "$file" ;;
73 | *\.mom) pdfroff -pktes -b -wall -mom -mpdfmark "$file" >"$base".pdf ;;
74 | *\.present) groff -p -e -t -mm -mpresent "$file" | presentps -l | ps2pdf - >"$base".pdf ;;
75 | *\.me) groff -Gktes -b -w w -me -T ps "$file" | ps2pdf - >"$base".pdf ;;
76 | *\.mm) groff -Gktes -b -w w -mm -mpic -T ps "$file" | ps2pdf - >"$base".pdf ;;
77 | *\.tex) textype "$file" ;;
78 | *\.org) Ifinstalled pandoc && pandocorg "$file" "$base" && exit ;;
79 | *\.md) Ifinstalled pandoc && pandoccmd "$file" "$base" && exit ;;
80 | *config.h) make && sudo make install ;;
81 | *\.hs) runghc "$file" ;;
82 | *\.c) compilec ;;
83 | *\.cpp)
84 | g++ -std=c++26 \
85 | -fconcepts-diagnostics-depth=2 \
86 | -Wpedantic -Wall -Wconversion -Wextra \
87 | -Wcast-align -Wcast-qual -Wctor-dtor-privacy \
88 | -Wdisabled-optimization -Wformat=2 -Winit-self \
89 | -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs \
90 | -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls \
91 | -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel \
92 | -Wstrict-overflow=5 -Wswitch-default -Wundef \
93 | -fsanitize=undefined -fsanitize=address \
94 | -o "${base##*/}" "$file" && ./"${base##*/}"
95 | ;;
96 | *\.h) compilec ;;
97 | *\.r) R -f "$file" ;;
98 | *\.java) javac "$file" && java "${base##*/}" ;;
99 | *\.js) node "$file" ;;
100 | *\.py) python "$file" ;;
101 | *\.tcl) tclsh "$file" ;;
102 | *\.docx | *\.doc)
103 | Ifinstalled libreoffice && lowriter --convert-to pdf "$file" && exit
104 | Ifinstalled pandoc && pandoccmd "$file" "$base" && exit
105 | ;;
106 | *\.dot | *\.gv) dot -Tsvg "$file" | convert svg:- "$base".eps ;;
107 | *\.go) go run "$file" ;;
108 | *\.rs) rustc -o "${base##*/}" "$file" && ./"${base##*/}" ;;
109 | *\.vim*) vint "$file" ;;
110 | *\.sent) setsid sent "$file" 2>/dev/null & ;;
111 | *\.html) refreshbrowser ;;
112 | *\.rkt) racket "$file" ;;
113 | *\.apl) apl -f "$file" ;;
114 | *\.fnl)
115 | echo "fennel --compile "$file" > "$base".lua"
116 | fennel --compile "$file" >"$base".lua
117 | ;;
118 | *) chmod +x "$file" && sed 1q "$file" | grep "^#!/" | sed "s/^#!//" | xargs -r -I % "$file" ;;
119 | esac
120 | # vim:ft=sh
121 |
--------------------------------------------------------------------------------
/cl-menu.ros:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #|-*- mode:lisp -*-|#
3 | #|
4 | exec ros -Q -- $0 "$@"
5 | |#
6 | #|
7 | This is the simple beginings to a dmenu written in Common Lisp because
8 | some times C just isn't enough.
9 |
10 | WARNING: This is not at all complete or even functional.
11 |
12 | To run this simply install Roswell and make this file executable.
13 |
14 | Roswell installation instructions:
15 | https://roswell.github.io/Installation.html
16 | |#
17 | (progn ;;init forms
18 | (ros:ensure-asdf)
19 | #+quicklisp(ql:quickload '(clx) :silent t)
20 | )
21 |
22 | (defpackage :ros.script.cl-menu.3849918680
23 | (:use :cl))
24 | (in-package :ros.script.cl-menu.3849918680)
25 | (in-package :xlib)
26 |
27 | ;; TODO Add multi monitor support utilizing the display-number
28 | ;; TODO Handle user input
29 | ;; TODO Implement sorting algorithm
30 | ;; TODO Properly handle events and close display
31 | (declaim (optimize (speed 3) (safety 1)))
32 |
33 | (defstruct (menu (:constructor create-menu (prompt font text window gcontext)))
34 | (prompt ">" :type string :read-only t)
35 | (font nil :type font :read-only t)
36 | (text "" :type string)
37 | (window nil :type window)
38 | (gcontext nil :type gcontext))
39 |
40 | (defun h-center-of-monitor (display)
41 | (let ((screen (display-default-screen display))
42 | (monitor-x (xlib/xinerama:screen-info-x
43 | (car (xlib/xinerama::xinerama-query-screens display)))))
44 | (truncate (+ monitor-x (screen-width screen))
45 | 2)))
46 |
47 | (defun get-text-width (font border text)
48 | (+ (text-width font text) (* 2 border)))
49 |
50 | (defun get-text-height (font border)
51 | (+ (max-char-ascent font)
52 | (max-char-descent font) (* 2 border)))
53 |
54 | (declaim (ftype (function (string string display &optional string) menu) make-menu))
55 | (defun make-menu (text prompt display &optional (font-name "fixed"))
56 | (progn
57 | (print display)
58 | (let* ((screen (display-default-screen display))
59 | (font (open-font display font-name))
60 | (border 1)
61 | (x (h-center-of-monitor display))
62 | (y 0)
63 | (bg (screen-black-pixel screen))
64 | (fg (screen-white-pixel screen))
65 | (win (create-window :parent (screen-root screen)
66 | ;; :override-redirect :on
67 | :save-under :on
68 | :x x :y y
69 | :width (get-text-width font border text) :height (get-text-height font border)
70 | :background bg
71 | :border fg
72 | :border-width border
73 | :colormap (screen-default-colormap screen)
74 | :bit-gravity :center
75 | :event-mask (make-event-mask :exposure
76 | :key-press
77 | :key-release
78 | :button-press
79 | )))
80 | (gcontext (create-gcontext :drawable win
81 | :background bg
82 | :foreground fg
83 | :font font)))
84 | (create-menu
85 | prompt
86 | font
87 | text
88 | win
89 | gcontext))))
90 |
91 | (declaim (ftype (function (menu display) t) display-menu))
92 | (defun display-menu (menu display)
93 | (progn
94 | (let ((font (menu-font menu))
95 | (text (menu-text menu))
96 | (width (get-text-width (menu-font menu) 1 (menu-text menu)))
97 | (gcontext (menu-gcontext menu)))
98 | (map-window (menu-window menu))
99 | ;; (loop for ev = (process-event display :handler
100 | ;; (lambda (&rest event-slots
101 | ;; &key event-key
102 | ;; &allow-other-keys)
103 | ;; (case event-key
104 | ;; ((or :key-release :key-press)
105 | ;; "hello")))
106 | ;; :timeout nil)
107 | ;; do (print ev))
108 | (event-case (display ;; :discard-p t :force-output-p t
109 | )
110 | (:key-press ()
111 | t)
112 | (:exposure ;; Come here on exposure events
113 | (window count)
114 | (when (zerop count) ;; Ignore all but the last exposure event
115 | (with-state (window)
116 | (let ((x (truncate (- (drawable-width window) width) 2))
117 | (y (truncate (- (+ (drawable-height window)
118 | (max-char-ascent font))
119 | (max-char-descent font))
120 | 2)))
121 | ;; Draw text centered in window
122 | (clear-area window)
123 | (draw-glyphs window gcontext x y text)))
124 | ;; Returning non-nil causes event-case to exit
125 | nil))
126 | (:button-press () t))
127 | ) ;; exit event-case
128 | (when display
129 | (close-display display :abort nil))))
130 |
131 | (declaim (ftype (function (string string &optional string) t) cl-menu))
132 | (defun cl-menu (text prompt &optional (font-name "fixed"))
133 | "Start cl-menu on HOST with STRING in FONT "
134 | (let ((display (open-display
135 | (car (get-default-display)))))
136 | (display-menu (make-menu text prompt display)
137 | display)))
138 |
139 | (defun main (&rest argv)
140 | (declare (ignorable argv))
141 | (cl-menu "hello world" "> "))
142 | ;;; vim: set ft=lisp lisp:
143 |
--------------------------------------------------------------------------------
/tools/tpb.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # demo: https://www.youtube.com/watch?v=IY56U1L6FCI
3 | # source: https://github.com/saironiq/shellscripts
4 | #
5 | # by Sairon Istyar, 2012
6 | # distributed under the GPLv3 license
7 | # http://www.opensource.org/licenses/gpl-3.0.html
8 | #
9 |
10 | ### CONFIGURATION ###
11 | # program to use for torrent download
12 | # magnet link to torrent will be appended
13 | # you can add -- at the end to indicate end of options
14 | # (if your program supports it, most do)
15 | program='/home/gavinok/.scripts/tools/transadd'
16 | TPB="https://proxtpb.art/"
17 |
18 | # show N first matches by default
19 | limit=25
20 |
21 | # colors
22 | # numbcolor=''
23 | # namecolor=''
24 | # sizecolor=''
25 | # seedcolor=''
26 | # peercolor=''
27 | # errocolor=''
28 | # mesgcolor=''
29 | # nonecolor=''
30 | numbcolor='\x1b[1;35m'
31 | namecolor='\x1b[1;33m'
32 | sizecolor='\x1b[1;36m'
33 | seedcolor='\x1b[1;31m'
34 | peercolor='\x1b[1;32m'
35 | errocolor='\x1b[1;31m'
36 | mesgcolor='\x1b[1;37m'
37 | nonecolor='\x1b[0m'
38 |
39 | # default ordering method
40 | # 1 - name ascending; 2 - name descending;
41 | # 3 - recent first; 4 - oldest first;
42 | # 5 - size descending; 6 - size ascending;
43 | # 7 - seeds descending; 8 - seeds ascending;
44 | # 9 - leechers descending; 10 - leechers ascending;
45 | orderby=7
46 | ### END CONFIGURATION ###
47 |
48 | thisfile="$0"
49 |
50 | printhelp() {
51 | echo -e "Usage:"
52 | echo -e "\t$thisfile [options] search query"
53 | echo
54 | echo
55 | echo -e "Available options:"
56 | echo -e "\t-h\t\tShow help"
57 | echo -e "\t-n [num]\tShow only first N results (default 15; max 100 [top] or 30 [search])"
58 | echo -e "\t-C\t\tDo not use colors"
59 | echo -e "\t-P [prog]\tSet torrent client command (\`-P torrent-client\` OR \`-P \"torrent-client --options\"\`)"
60 | echo
61 | echo -e "Current client settings: $program [magnet link]"
62 | }
63 |
64 | # change torrent client
65 | chex() {
66 | sed "s!^program=.*!program=\'$program\'!" -i "$thisfile"
67 | if [ $? -eq 0 ] ; then
68 | echo "Client changed successfully."
69 | exit 0
70 | else
71 | echo -e "${errocolor}(EE) ${mesgcolor}==> Something went wrong!${nonecolor}"
72 | exit 1
73 | fi
74 | }
75 |
76 | # script cmdline option handling
77 | while getopts :hn:CP:: opt ; do
78 | case "$opt" in
79 | h) printhelp; exit 0;;
80 | n) limit="$OPTARG";;
81 | C) unset numbcolor namecolor sizecolor seedcolor peercolor nonecolor errocolor mesgcolor;;
82 | P) program="$OPTARG"; chex;;
83 | *) echo -e "Unknown option(s)."; printhelp; exit 1;;
84 | esac
85 | done
86 |
87 | shift `expr $OPTIND - 1`
88 |
89 | # correctly encode query
90 | q=`echo "$*" | tr -d '\n' | od -t x1 -A n | tr ' ' '%'`
91 |
92 | # if not searching, show top torrents
93 | if [ -z "$q" ] ; then
94 | url="top/all"
95 | else
96 | url='search/'"$q"'/0/'"$orderby"'/0'
97 | fi
98 |
99 | # get results
100 | # Here be dragons!
101 | r=`curl -k -A Mozilla -b "lw=s" -m 15 -s "$TPB/$url" \
102 | | grep -Eo '^| ]*>.*|^ | [^<]*' \
103 | | sed 's!^| ]*>!!; \
104 | s!$!!; \
105 | s!^ | ]*>!!; \
107 | s! !\ !g; \
108 | s/|/!/g' \
109 | | sed 'N;N;N;N;s!\n!|!g'`
110 |
111 | # number of results
112 | n=`echo "$r" | wc -l`
113 |
114 | IFS=$'\n'
115 |
116 | # print results
117 | echo "$r" \
118 | | head -n "$limit" \
119 | | awk -v N=1 \
120 | -v NU="$numbcolor" \
121 | -v NA="$namecolor" \
122 | -v SI="$sizecolor" \
123 | -v SE="$seedcolor" \
124 | -v PE="$peercolor" \
125 | -v NO="$nonecolor" \
126 | -F '|' \
127 | '{print NU N ") " NA $1 " " SI $3 " " SE $4 " " PE $5 NO; N++}'
128 |
129 | # read ID(s), expand ranges, ignore everything else
130 | read -p ">> Torrents to download (eg. 1 3 5-7): " selection
131 | IFS=$'\n\ '
132 | for num in $selection ; do
133 | if [ "$num" = "`echo "$num" | grep -o '[[:digit:]][[:digit:]]*'`" ] ; then
134 | down="$down $num"
135 | elif [ "$num" = "`echo "$num" | grep -o '[[:digit:]][[:digit:]]*-[[:digit:]][[:digit:]]*'`" ] ; then
136 | seqstart="${num%-*}"
137 | seqend="${num#*-}"
138 | if [ "$seqstart" -le "$seqend" ] ; then
139 | down=""$down" `seq "$seqstart" "$seqend"`"
140 | fi
141 | fi
142 | done
143 |
144 | # normalize download list, sort it and remove dupes
145 | down="$(echo "$down" | tr '\ ' '\n' | sort -n | uniq)"
146 | IFS=$'\n'
147 |
148 | # check whether we're downloading something, else exit
149 | if [ -z "$down" ] ; then
150 | exit 0
151 | fi
152 |
153 | # download all torrents in list
154 | echo -n "Downloading torrent(s): "
155 | for torrent in $down ; do
156 | # check if ID is valid and in range of results, download torrent
157 | if [ "$torrent" -ge 1 ] ; then
158 | if [ "$torrent" -le "$limit" ] ; then
159 | echo -n "$torrent "
160 | command=""$program" `echo "$r" | awk -F '|' 'NR=='$torrent'{print $2; exit}'`"
161 | status=$(eval "$command" 2>&1)
162 | if [ $? -ne 0 ] ; then
163 | echo -n '(failed!) '
164 | report=""$report"\n(#$torrent) $status"
165 | fi
166 | fi
167 | fi
168 | done
169 | echo
170 | if [ -n "$report" ] ; then
171 | echo -n "Exited with errors:"
172 | echo -e "$report"
173 | fi
174 | unset IFS
175 | # vim:ft=sh
176 |
--------------------------------------------------------------------------------
/dmenu/tutorialvids:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # LAUNCER="dmenu -i -l 20 -p "
4 | LAUNCER="emenu -p "
5 | [ -z "${DISPLAY}" ] && LAUNCER="fzf --prompt"
6 |
7 | vidlist="
8 | Bash script https://www.youtube.com/watch?v=YOpeXETS2z0&t=192s
9 | Bash script full https://www.youtube.com/watch?v=oxuRxtrO2Ag
10 | dmenu script https://www.youtube.com/watch?v=R9m723tAurA
11 | status bar https://www.youtube.com/watch?v=gKumet6b-WY
12 | mutt https://www.youtube.com/watch?v=2U3vRbF7v5A
13 | ncmpcpp https://www.youtube.com/watch?v=sZIEdI9TS2U
14 | newsboat https://www.youtube.com/watch?v=dUFCRqs822w
15 | ranger https://www.youtube.com/watch?v=L6Vu7WPkoJo
16 | gpg keys https://www.youtube.com/watch?v=DMGIlj7u7Eo
17 | urlview https://www.youtube.com/watch?v=IgzpAjFgbCw
18 | ncurses https://www.youtube.com/watch?v=2tWN6ntNo4w
19 | SQL https://www.youtube.com/watch?v=bEtnYWuo2Bw
20 | SQL Full https://www.youtube.com/watch?v=HXV3zeQKqGY&t=4342s
21 | C programming https://www.youtube.com/watch?v=2NWeucMKrLI&index=1&list=PL6gx4Cwl9DGAKIXv8Yr6nhGJ9Vlcjyymq
22 | C File I/O https://www.youtube.com/watch?v=-LqUMHoBo6o
23 | C Error Handling https://www.youtube.com/watch?v=IZiUT-ipnj0
24 | install latex https://www.youtube.com/watch?v=NwnYHoNtfJ0
25 | Latex all https://m.youtube.com/watch?v=VhmkLrOjLsw
26 | Latex1 https://www.youtube.com/watch?v=mfRmmZ_84Mw&t=2s
27 | Latex2 https://www.youtube.com/watch?v=25LExaNtdF0
28 | Latex bib https://www.youtube.com/watch?v=46piog3Fzp4
29 | Latex Resume https://www.youtube.com/watch?v=VjsX4tznW40&t=570s
30 | Latex Resume2 https://www.youtube.com/watch?v=o5-BZ7JmYWk
31 | Latex Images https://www.youtube.com/watch?v=zgThRPjy-vw
32 | Latex Macros https://www.youtube.com/watch?v=rvgP7IMeUn8
33 | Latex and vim https://www.youtube.com/watch?v=yNOkCYuPt3E
34 | Python https://www.youtube.com/watch?v=rfscVS0vtbw&t=2s
35 | JSON https://www.youtube.com/watch?v=wI1CWzNtE-M
36 | JavaScript https://www.youtube.com/watch?v=W6NZfCO5SIk
37 | Go 7 hour Course https://www.youtube.com/watch?v=YS4e4q9oBaU&t=2h19m0s
38 | Regex https://www.youtube.com/watch?v=vcRPNhLbhoc
39 | Game Dev in C https://www.youtube.com/watch?v=yFLa3ln16w0&t=556s
40 | Red Hat Linux Course complete https://www.youtube.com/watch?v=oflN6WZOzxw
41 | Full ArchLinux Install https://www.youtube.com/watch?v=4PBqpX0_UOc&t=1473s
42 | Power of Unix https://www.youtube.com/watch?v=7uwW20odwEk
43 | Manjaro Architect https://www.youtube.com/watch?v=530O4InhR3A
44 | POSIX pthreads https://www.youtube.com/watch?v=ynCc-v0K-do&list=PLzCAxcRKUAgkc65DlRo0gr0B8sqlE6WZY
45 | groff https://www.youtube.com/watch?v=w8EKH_fjmXA
46 | groff Macros and Others https://www.youtube.com/watch?v=kJ_TXZB4Gm4
47 | groff refer https://www.youtube.com/watch?v=XfOwRYmb5bQ&list=PL-p5XmQHB_JRe2YeaMjPTKXSc5FqJZ_km&index=4&t=0s
48 | groff auto refer https://www.youtube.com/watch?v=yTQbi_E_Gys&list=PL-p5XmQHB_JRe2YeaMjPTKXSc5FqJZ_km&index=4
49 | eqn groff https://www.youtube.com/watch?v=sp0qgpeG6EY
50 | rclone https://www.youtube.com/watch?v=G8YMspboIXs
51 | Arch Linux Maintenance https://www.youtube.com/watch?v=3BnHHP7Fmo0
52 | Awk https://www.youtube.com/watch?v=_q6Uj4X_knc
53 | Hacking with Vim https://www.youtube.com/watch?v=l8iXMgk2nnY
54 | mutt isync https://www.youtube.com/watch?v=tR9zk3xz5SA
55 | ffmpeg screen casting https://www.youtube.com/watch?v=386Z2yeQ5fo
56 | installing fonts https://www.youtube.com/watch?v=LJ7CEhnS0OM
57 | cs50 Beyond javascript https://www.youtube.com/watch?v=dlEPkLSDQi0&t=51s
58 | cs50 Beyond javascript continued https://www.youtube.com/watch?v=XNDZ3eg_VcE&t=319s
59 | spotifyd https://www.youtube.com/watch?v=R5jikGfSdh4
60 | hugo netlify github pages https://www.youtube.com/watch?v=NSts93C9UeE
61 | Lua https://www.youtube.com/watch?v=iMacxZQMPXs
62 | Gnu Parallel https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1
63 | Curl for REST APIs https://www.youtube.com/watch?v=czeIHABQCxo
64 | ImageMagick transparency https://www.youtube.com/watch?v=D8pcvkRsx1g&t=300s
65 | ImageMagick Canvases, Plasma, Composites, Geometry https://www.youtube.com/watch?v=nbXHbHrfrIs
66 | hub https://www.youtube.com/watch?v=xWbaKNFAh8Y
67 | valgrind https://www.youtube.com/watch?v=bb1bTJtgXrI
68 | pass https://www.youtube.com/watch?v=sVkURNfxPd4
69 | discord bridge https://www.youtube.com/watch?v=xIOyc4Rklqc&t=317s
70 | "
71 |
72 | pdfs="
73 | pic for image drawing PDF http://floppsie.comp.glam.ac.uk/Glamorgan/gaius/web/pic.html
74 | pic Revised User Manual PDF http://doc.cat-v.org/unix/v8/picmemo.pdf
75 | tbl PDF http://doc.cat-v.org/unix/v10/10thEdMan/tbl.pdf
76 | eqn PDF http://www.kohala.com/start/troff/v7man/eqn/eqn2e.ps
77 | refer PDF http://www.kohala.com/start/troff/v7man/refer/refer.ps
78 | grap PDF http://doc.cat-v.org/unix/v8/grap.pdf
79 | unix text processing (utp) PDF https://github.com/larrykollar/Unix-Text-Processing/releases/download/1.0/utp-1.0.pdf
80 | pdf manipulation in groff with pdfmark PDF http://pipeline.lbl.gov/code/3rd_party/licenses.win/groff/1.19.2/pdf/pdfmark.pdf
81 | pdfmark.ms PDF http://git.savannah.gnu.org/cgit/groff.git/plain/contrib/pdfmark/pdfmark.ms
82 | general troff tutorial PDF http://www.kohala.com/start/troff/v7man/trofftut/trofftut.ps
83 | Troff User Manual PDF http://doc.cat-v.org/plan_9/4th_edition/papers/troff.pdf
84 | Groff and Friends HOWTO PDF https://www.troff.org/TheGroffFriendsHowto.pdf
85 | mom macros PDF http://www.schaffter.ca/mom/pdf/mom-pdf.pdf
86 | ms macros PDF http://www.kohala.com/start/troff/v7man/msmacros/msmacros.ps
87 | "
88 | tutorials="
89 | ${vidlist}
90 | ${pdfs}
91 | "
92 |
93 | # TODO: grep for youtube to determin if it should use ytplay or xdg-open
94 | if command -v www >/dev/null; then
95 | Player='www'
96 | else
97 | Player='xdg-open'
98 | fi
99 | echo "${tutorials}" | grep -P "^$(echo "${tutorials}" | grep "https\?:" | sed 's/\t.*//g' | ${LAUNCER} "Learn about what?" | cut -f1)\t" | sed 's/.*\t//' | xargs -r ${Player}
100 | #vim:ft=sh
101 |
--------------------------------------------------------------------------------
/dwm/colortheme:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | set -e
3 |
4 | version="0.1.0"
5 | slroot=~
6 |
7 | die() {
8 | printf '%s \n' "$1" >&2
9 | exit 1
10 | }
11 |
12 | show_help() {
13 | echo "usage: ${0##*/} [OPTION] THEMEFILE"
14 | echo "Writes colors from THEMEFILE to:"
15 | echo " ~/.Xresources"
16 | # echo " $slroot/st/config.h"
17 | # echo " $slroot/tabbed/config.h"
18 | # echo " $slroot/dwm/config.h"
19 | echo "Valid OPTIONS are:"
20 | echo " -h, --help show this message"
21 | echo " -v, --version show version information"
22 | }
23 |
24 | show_version() {
25 | echo "${0##*/} version $version"
26 | echo "Licensed under GNU Public License v3+"
27 | echo "Written by Anders Damsgaard "
28 | }
29 |
30 | get_theme_color() {
31 | ! [ -f "$path" ] && die "Error: Could not find $path"
32 | grep --ignore-case "^\*\.*$1:" "$path" | awk '{ print $2 }'
33 | }
34 |
35 | report_colors() {
36 | echo "foreground: $foreground"
37 | echo "background: $background"
38 | echo "color0: $color0"
39 | echo "color1: $color1"
40 | echo "color2: $color2"
41 | echo "color3: $color3"
42 | echo "color4: $color4"
43 | echo "color5: $color5"
44 | echo "color6: $color6"
45 | echo "color7: $color7"
46 | echo "color8: $color8"
47 | echo "color9: $color9"
48 | echo "color10: $color10"
49 | echo "color11: $color11"
50 | echo "color12: $color12"
51 | echo "color13: $color13"
52 | echo "color14: $color14"
53 | echo "color15: $color15"
54 | echo "cursorColor: $cursorColor"
55 | }
56 |
57 | get_colors() {
58 | path="$1"
59 | ! [ -f "$path" ] && die "Error: Could not find $path"
60 | foreground=$(get_theme_color foreground)
61 | background=$(get_theme_color background)
62 | echo $background
63 | color0=$(get_theme_color color0)
64 | color1=$(get_theme_color color1)
65 | color2=$(get_theme_color color2)
66 | color3=$(get_theme_color color3)
67 | color4=$(get_theme_color color4)
68 | color5=$(get_theme_color color5)
69 | color6=$(get_theme_color color6)
70 | color7=$(get_theme_color color7)
71 | color8=$(get_theme_color color8)
72 | color9=$(get_theme_color color9)
73 | color10=$(get_theme_color color10)
74 | color11=$(get_theme_color color11)
75 | color12=$(get_theme_color color12)
76 | color13=$(get_theme_color color13)
77 | color14=$(get_theme_color color14)
78 | color15=$(get_theme_color color15)
79 | cursorColor=$(get_theme_color cursorColor)
80 | cursorColor=${cursorColor:-#FF00FF}
81 |
82 | if [ "$foreground" = "" ] || \
83 | [ "$background" = "" ] || \
84 | [ "$color0" = "" ] || \
85 | [ "$color1" = "" ] || \
86 | [ "$color2" = "" ] || \
87 | [ "$color3" = "" ] || \
88 | [ "$color4" = "" ] || \
89 | [ "$color5" = "" ] || \
90 | [ "$color6" = "" ] || \
91 | [ "$color7" = "" ] || \
92 | [ "$color8" = "" ] || \
93 | [ "$color9" = "" ] || \
94 | [ "$color10" = "" ] || \
95 | [ "$color11" = "" ] || \
96 | [ "$color12" = "" ] || \
97 | [ "$color13" = "" ] || \
98 | [ "$color14" = "" ] || \
99 | [ "$color15" = "" ] || \
100 | [ "$cursorColor" = "" ]; then
101 |
102 | report_colors
103 | die 'Error: One or more colors were not defined'
104 | fi
105 | }
106 |
107 | set_colors() {
108 | get_colors "$1"
109 |
110 | if [ -f ~/.Xresources ]; then
111 | sed -i "s/^\*\.foreground: .*$/\*.foreground: $foreground/;\
112 | s/^\*\.background: .*$/\*.background: $background/;\
113 | s/^\*\.color0: .*$/\*.color0: $color0/;\
114 | s/^\*\.color1: .*$/\*.color1: $color1/;\
115 | s/^\*\.color2: .*$/\*.color2: $color2/;\
116 | s/^\*\.color3: .*$/\*.color3: $color3/;\
117 | s/^\*\.color4: .*$/\*.color4: $color4/;\
118 | s/^\*\.color5: .*$/\*.color5: $color5/;\
119 | s/^\*\.color6: .*$/\*.color6: $color6/;\
120 | s/^\*\.color7: .*$/\*.color7: $color7/;\
121 | s/^\*\.color8: .*$/\*.color8: $color8/;\
122 | s/^\*\.color9: .*$/\*.color9: $color9/;\
123 | s/^\*\.color10: .*$/\*.color10: $color10/;\
124 | s/^\*\.color11: .*$/\*.color11: $color11/;\
125 | s/^\*\.color12: .*$/\*.color12: $color12/;\
126 | s/^\*\.color13: .*$/\*.color13: $color13/;\
127 | s/^\*\.color14: .*$/\*.color14: $color14/;\
128 | s/^\*\.color15: .*$/\*.color15: $color15/;\
129 | s/^\*\.cursorColor: .*$/\*.cursorColor: $cursorColor/" ~/.Xresources
130 | xrdb -merge ~/.Xresources
131 | command -v i3-msg >/dev/null 2>&1 && (i3-msg restart || :)
132 | command -v wallpaper >/dev/null 2>&1 && (wallpaper || :)
133 | fi
134 |
135 | # if [ -f $slroot/st/config.h ]; then
136 | # sed -i "s/^\t\[257\] = \".*\",.*$/\t\[257\] = \"$foreground\",/;\
137 | # s/^\t\[256\] = \".*\",.*$/\t\[256\] = \"$background\",/;\
138 | # s/^\t\[0\] = \".*\",.*$/\t\[0\] = \"$color0\",/;\
139 | # s/^\t\[1\] = \".*\",.*$/\t\[1\] = \"$color1\",/;\
140 | # s/^\t\[2\] = \".*\",.*$/\t\[2\] = \"$color2\",/;\
141 | # s/^\t\[3\] = \".*\",.*$/\t\[3\] = \"$color3\",/;\
142 | # s/^\t\[4\] = \".*\",.*$/\t\[4\] = \"$color4\",/;\
143 | # s/^\t\[5\] = \".*\",.*$/\t\[5\] = \"$color5\",/;\
144 | # s/^\t\[6\] = \".*\",.*$/\t\[6\] = \"$color6\",/;\
145 | # s/^\t\[7\] = \".*\",.*$/\t\[7\] = \"$color7\",/;\
146 | # s/^\t\[8\] = \".*\",.*$/\t\[8\] = \"$color8\",/;\
147 | # s/^\t\[9\] = \".*\",.*$/\t\[9\] = \"$color9\",/;\
148 | # s/^\t\[10\] = \".*\",.*$/\t\[10\] = \"$color10\",/;\
149 | # s/^\t\[11\] = \".*\",.*$/\t\[11\] = \"$color11\",/;\
150 | # s/^\t\[12\] = \".*\",.*$/\t\[12\] = \"$color12\",/;\
151 | # s/^\t\[13\] = \".*\",.*$/\t\[13\] = \"$color13\",/;\
152 | # s/^\t\[14\] = \".*\",.*$/\t\[14\] = \"$color14\",/;\
153 | # s/^\t\[258\] = \".*\",.*$/\t\[258\] = \"$cursorColor\",/"\
154 | # $slroot/st/config.h
155 | # fi
156 |
157 | # if [ -f $slroot/tabbed/config.h ]; then
158 | # sed -i "s/normbgcolor \+= \".*\";/normbgcolor = \"$background\";/;\
159 | # s/normfgcolor \+= \".*\";/normfgcolor = \"$foreground\";/;\
160 | # s/selfgcolor \+= \".*\";/selfgcolor = \"$background\";/;\
161 | # s/selbgcolor \+= \".*\";/selbgcolor = \"$foreground\";/;\
162 | # s/urgbgcolor \+= \".*\";/urgbgcolor = \"$color9\";/;\
163 | # s/urgfgcolor \+= \".*\";/urgfgcolor = \"$color0\";/"\
164 | # $slroot/tabbed/config.h
165 | # fi
166 |
167 |
168 | if [ -f $slroot/dwm/config.h ]; then
169 | sed -i "s/col_gray4\[\] *= \".*\";/col_gray4\[\] = \"$background\";/;\
170 | s/col_cyan\[\] *= \".*\";/col_cyan\[\] = \"$color6\";/;\
171 | s/col_gray3\[\] *= \".*\";/col_gray3\[\] = \"$foreground\";/;\
172 | s/col_gray1\[\] *= \".*\";/col_gray1\[\] = \"$background\";/;"\
173 | $slroot/dwm/config.h
174 | fi
175 |
176 | }
177 |
178 | [ $# -lt 1 ] && (show_help && exit 1)
179 |
180 | while :; do
181 | case "$1" in
182 | -h|-\?|--help)
183 | show_help
184 | exit 0
185 | ;;
186 | -v|--version)
187 | show_version
188 | exit 0
189 | ;;
190 | --) # end all options
191 | shift
192 | break
193 | ;;
194 | -?*)
195 | die "Error: Unknown option '$1' specified"
196 | ;;
197 | *) # no more options
198 | break
199 | esac
200 | shift
201 | done
202 |
203 | [ $# -lt 1 ] && die 'Error: No THEMEFILE specified'
204 | [ $# -gt 1 ] && die 'Error: More than one THEMEFILE specified'
205 |
206 | set_colors "$1"
207 | #vim:ft=sh
208 |
--------------------------------------------------------------------------------
/dmenu/dmenu_kdeconnect.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | # dmenu_kdeconnect.sh is a script based off of these scripts
3 | # [polybar-kdeconnect] https://github.com/HackeSta/polybar-kdeconnect
4 | # [polybar-kdeconnect-scripts] https://github.com/witty91/polybar-kdeconnect-scripts
5 | # Added features
6 | # - Removed polybar as a Dependencies (since I use dwm)
7 | # - Integration with a variety of file managers
8 | # - Implementation as one simplified shell script
9 | # - utilize sh instead of bash
10 |
11 | #TODO
12 | # 1. Allow different dmenu colors based on the battery percentage
13 | # 2. Make the script no sh complaint
14 | # 3. Implement a contacts list to make sms messaging easier
15 |
16 | # Dependancies
17 | # -dmenu
18 | # -kdeconnect
19 | # -zenity, nnn, or ranger
20 | # -qt5-tools
21 | # -dbus
22 | # -dunst
23 |
24 | # options
25 | # nnn
26 | # zenity
27 | # ranger
28 | Picker='zenity'
29 |
30 | # Color Settings of dmenu
31 | COLOR_DISCONNECTED='#000' # Device Disconnected
32 | COLOR_NEWDEVICE='#ff0' # New Device
33 | COLOR_BATTERY_90='#fff' # Battery >= 90
34 | COLOR_BATTERY_80='#ccc' # Battery >= 80
35 | COLOR_BATTERY_70='#aaa' # Battery >= 70
36 | COLOR_BATTERY_60='#888' # Battery >= 60
37 | COLOR_BATTERY_50='#666' # Battery >= 50
38 | COLOR_BATTERY_LOW='#f00' # Battery < 50
39 |
40 | # Icons shown in dmenu
41 | ICON_SMARTPHONE=''
42 | ICON_TABLET=''
43 | SEPERATOR='|'
44 |
45 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
46 |
47 | ping -q -c 1 1.1.1.1 > /dev/null || "$(notify-send "check internet connection" && exit)"
48 |
49 | show_devices (){
50 | IFS=$','
51 | devices=""
52 | # for all the devices avalable
53 | for device in $(qdbus --literal org.kde.kdeconnect /modules/kdeconnect org.kde.kdeconnect.daemon.devices); do
54 | #get the device info
55 | deviceid=$(echo "$device" | awk -F'["|"]' '{print $2}')
56 | devicename=$(qdbus org.kde.kdeconnect /modules/kdeconnect/devices/$deviceid org.kde.kdeconnect.device.name)
57 | devicetype=$(qdbus org.kde.kdeconnect /modules/kdeconnect/devices/$deviceid org.kde.kdeconnect.device.type)
58 | isreach="$(qdbus org.kde.kdeconnect /modules/kdeconnect/devices/$deviceid org.kde.kdeconnect.device.isReachable)"
59 | istrust="$(qdbus org.kde.kdeconnect /modules/kdeconnect/devices/$deviceid org.kde.kdeconnect.device.isTrusted)"
60 | if [ "$isreach" = "true" ] && [ "$istrust" = "true" ];then
61 | #is connected
62 | battery="$(qdbus org.kde.kdeconnect /modules/kdeconnect/devices/$deviceid org.kde.kdeconnect.device.battery.charge)%"
63 | icon=$(get_icon $battery $devicetype)
64 | # colors="$(get_colors $battery)"
65 | # echo "$colors"
66 | show_menu "$devicename | $battery $icon" $deviceid $battery
67 | devices+="$devicename $battery $icon $SEPERATOR"
68 | elif [ "$isreach" = "false" ] && [ "$istrust" = "true" ];then
69 | #nothing is found
70 | devices+="$(get_icon -1 $devicetype)$SEPERATOR"
71 | else
72 | #found but not yet paired
73 | icon=$(get_icon -2 $devicetype)
74 | show_pmenu $devicename $deviceid
75 | devices+="$devicename $icon $SEPERATOR"
76 | fi
77 | done
78 | }
79 |
80 | SendKeys(){
81 | output="?"
82 | TEMPFILE=/tmp/VimFloat
83 | > $TEMPFILE
84 | st -t "vim-anywhere" -n 'popup' -e "${EDITOR:-vi}" -c 'startinsert' $TEMPFILE
85 | xsel -i < $TEMPFILE
86 | output=$(xsel -o)
87 | notify-send "$output"
88 | kdeconnect-cli --device "$*" -k "$output"
89 | }
90 |
91 | #used to interact with notifications if they are avalable
92 | Notification_menu () {
93 | replyable=`qdbus org.kde.kdeconnect /modules/kdeconnect/devices/$2/notifications/$1 org.kde.kdeconnect.device.notifications.notification.replyId`
94 | echo $replyable
95 | options=$(printf "View\\nDissmiss")
96 | if [ "$replyable" ]; then
97 | options+=$(printf "\\nReply")
98 | optionNum=$((optionNum+1))
99 | fi
100 | ticker1=`qdbus org.kde.kdeconnect /modules/kdeconnect/devices/$2/notifications/$1 org.kde.kdeconnect.device.notifications.notification.ticker`
101 | prompt=$(echo $ticker1 | cut -c 1-100)
102 | menu=$(echo $options | dmenu -i -p "$prompt" -l $optionNum )
103 | case "$menu" in
104 | *'View' )
105 | ticker1=`qdbus org.kde.kdeconnect /modules/kdeconnect/devices/$2/notifications/$1 org.kde.kdeconnect.device.notifications.notification.ticker`
106 | notify-send "$ticker1";;
107 | *'Dissmiss')
108 | qdbus org.kde.kdeconnect /modules/kdeconnect/devices/$2/notifications/$1 org.kde.kdeconnect.device.notifications.notification.dismiss;;
109 | *'Reply' )
110 | qdbus org.kde.kdeconnect /modules/kdeconnect/devices/$2/notifications/$1 org.kde.kdeconnect.device.notifications.notification.reply;;
111 | esac
112 | }
113 |
114 | #displays a menu for the connected device
115 | show_menu () {
116 | optionNum=5
117 | options=$(printf "Send SMS\\nSend File\\nFind Device\\nPing\\nUnpair\\nkeys\\n")
118 | notification1=`dbus-send --session --print-reply --dest="org.kde.kdeconnect" /modules/kdeconnect/devices/$2 org.kde.kdeconnect.device.notifications.activeNotifications|tr '\n' ' ' | awk '{print $12}'| sed s/\"//g`
119 | if [ $notification1 ]; then
120 | options+=$(printf "\\nNotification")
121 | optionNum=$((optionNum+1))
122 | fi
123 | options+=$(printf "\\nRefresh\\n")
124 | menu=$(echo $options | dmenu -i -p $1 -l $optionNum )
125 | case "$menu" in
126 | *'Ping')
127 | message=$(echo 'Ping' | dmenu -i -p "Msg to send")
128 | kdeconnect-cli --ping-msg "$message" -d $2;;
129 | *'Find Device') kdeconnect-cli --ring -d $2 ;;
130 | *'Send File')
131 | [ $Picker == 'nnn' ] && kdeconnect-cli --share "file://$($TERMINAL nnn -p -)" -d $2 ;
132 | [ $Picker == 'zenity' ] && kdeconnect-cli --share "file://$(zenity --file-selection)" -d $2 ;
133 | if [ $Picker == 'ranger' ]; then
134 | mkdir -p /tmp/ranger/ && touch /tmp/ranger/sentfile
135 | kdeconnect-cli --share "file://$($TERMINAL ranger --choosefile=/tmp/ranger/sentfile)" -d $2
136 | fi;;
137 | *'Unpair' ) kdeconnect-cli --unpair -d $2 ;;
138 | *'Send SMS' )
139 | message=$(echo 'OTW' | dmenu -i -p "Msg to send")
140 | recipient=$(echo '14039199518' | dmenu -i -p "Recipient's phone #")
141 | kdeconnect-cli --send-sms "$message" --destination "$recipient" -d $2 ;;
142 | *'Refresh' )
143 | kdeconnect-cli --refresh;;
144 | *'Notification' )
145 | Notification_menu $notification1 $2;;
146 | *'keys' )
147 | SendKeys "$2";;
148 | esac
149 | }
150 |
151 | show_pmenu () {
152 | menu="$(printf "Pair Device" | dmenu -i -p "$1" )"
153 | case "$menu" in
154 | *'Pair Device') kdeconnect-cli --pair -d $2 ;;
155 | esac
156 | }
157 | #still a work in progress
158 | # get_colors () {
159 | # case $1 in
160 | # "-1") colors="-nb \"$COLOR_DISCONNECTED\" -nf \"#000\" " ;;
161 | # "-2") colors="-nb \"$COLOR_NEWDEVICE\" -nf \"#000\" ";;
162 | # 5*) colors="-nb \"$COLOR_BATTERY_50\" -nf \"#000\" ";;
163 | # 6*) colors="-nb \"$COLOR_BATTERY_60\" -nf \"#000\" ";;
164 | # 7*) colors="-nb \"$COLOR_BATTERY_70\" -nf \"#000\" ";;
165 | # 8*) colors="-nb \"$COLOR_BATTERY_80\" -nf \"#000\" ";;
166 | # *) colors="-nb \"$COLOR_BATTERY_LOW\" -nf \"#000\" ";;
167 | # 9*|100) colors="-nb \"$COLOR_BATTERY_90\" -nf \"#000\" ";;
168 | # esac
169 | # echo $colors
170 | # }
171 |
172 | get_icon () {
173 | if [ "$2" = "tablet" ]
174 | then
175 | ICON=$ICON_TABLET
176 | else
177 | ICON=$ICON_SMARTPHONE
178 | fi
179 | echo $ICON
180 | }
181 | show_devices
182 | #vim:ft=sh
183 |
--------------------------------------------------------------------------------
| |