diff options
author | filip <“filip.rabiega@gmail.com”> | 2025-10-14 21:57:25 +0200 |
---|---|---|
committer | filip <“filip.rabiega@gmail.com”> | 2025-10-14 21:57:25 +0200 |
commit | 91a4eacb0419bd0f67774f6124b6f0b1525eb988 (patch) | |
tree | de8189790a11437e540f7792fd7559f88212bae7 | |
parent | 7f6189dcbed755af34e222237b8cfa8b1f903696 (diff) | |
download | chadscripts-91a4eacb0419bd0f67774f6124b6f0b1525eb988.tar.gz chadscripts-91a4eacb0419bd0f67774f6124b6f0b1525eb988.tar.bz2 chadscripts-91a4eacb0419bd0f67774f6124b6f0b1525eb988.zip |
new stuff
-rwxr-xr-x | dbdb | 18 | ||||
-rwxr-xr-x | dpass | 5 | ||||
-rwxr-xr-x | late | 150 | ||||
-rwxr-xr-x | notesplain | 2 | ||||
-rwxr-xr-x | slp | 3 | ||||
-rwxr-xr-x | todo | 28 | ||||
-rwxr-xr-x | via | 15 | ||||
-rwxr-xr-x | via-feed | 12 | ||||
-rwxr-xr-x | via-menu | 3 | ||||
-rwxr-xr-x | via-open | 56 |
10 files changed, 291 insertions, 1 deletions
@@ -0,0 +1,18 @@ +#!/bin/sh +# dmenu-based directory browser +# to run from terminal: +# source /path/to/dbdb.sh +# or bind it to shortcut: +# echo bind \'\"\\C-o\":\"source /path/to/dbdb.sh\\n\"\' >> ~/.bashrc + +chosen="placeholder" + +while [ ! -z "$chosen" ]; do + DIRs=$( ls -a1p | grep -P '^\w[^\$/]+/$' | awk -vRS="\n" -vORS="\t" '1') + DOTDs=$( ls -a1p | grep -P '^\.[^\$/]+/$' | awk -vRS="\n" -vORS="\t" '1') + FILEs=$( ls -a1p | grep -P '^\w[^\$/]+$' | awk -vRS="\n" -vORS=" \t" '1') + DOTFs=$( ls -a1p | grep -P '^\.[^\$/]+$' | awk -vRS="\n" -vORS=" \t" '1') + clear && printf "\e[1;7;33m $(pwd) \e[0m\n$FILEs\n\e[0;38;5;238m$DOTFs\e[0m\n" + chosen=`( ( echo -e "$DIRs$DOTDs" | awk -vRS="\t" -vORS="\n" '1' ) | dmenu -i )` + cd "$chosen" +done @@ -0,0 +1,5 @@ +#!/bin/sh + +password=$(find ~/.password-store/ -type f -name '*.gpg' | + sed 's/.*\/\(.*\)\.gpg$/\1/' | dmenu -i -p "Pass:") +[ -n "$password" ] && pass show -c "$password" @@ -0,0 +1,150 @@ +#!/bin/sh + +echo_err() { + notify-send -u critical "$0 error" "$1" +} + +err() { + echo_err "$1" + exit 1 +} + +check_dep() { + command -v "$1" > /dev/null || err "$1 is required: $2" +} + +# We don't check if dmenu is installed because someone +# may want to replace it via DMENU vars +check_dep trans https://github.com/soimort/translate-shell +check_dep notify-send + +load_config() { + config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/dmenu-translate" + [ -d "$config_dir" ] || mkdir -p "$config_dir" + + config_file="$config_dir/config.sh" + [ -f "$config_file" ] || touch "$config_file" + + old_config_file="$config_dir/config.conf" + [ -f "$old_config_file" ] && notify-send "dmenu-translate warning" "Found old configuration file at <code>$old_config_file</code>, which is no longer supported. Please move your settings to a new file at <code>$config_file</code> and delete the old one." + + . "$config_file" + + # Check others + if [ -n "$WAYLAND_DISPLAY" ]; then + : "${CLIP_COPY:=wl-copy -n}" + : "${CLIP_PASTE_CLIP:=wl-paste}" + : "${CLIP_PASTE_PRIM:=wl-paste -p}" + : "${DMENU:=wmenu}" + : "${TERMINAL=foot}" + else + : "${CLIP_COPY:=xclip -i -r -selection clipboard}" + : "${CLIP_PASTE_CLIP:=xclip -o -selection clipboard}" + : "${CLIP_PASTE_PRIM:=xclip -o -selection primary}" + : "${DMENU:=dmenu}" + : "${TERMINAL=xterm}" + fi + + # Default values + : "${TRANS_LANGS:=:ru :en}" + : "${DMENU_TEXT:=${DMENU} -i -p 'Translate: Text'}" + : "${DMENU_LANG:=${DMENU} -i -p 'Translate: Into'}" + : "${DMENU_NEXT:=${DMENU} -i -p 'Translate: Next?'}" +} + +formatmenu() { + echo "$1" | tr '\n' ' ' | sed 's/\s\{3,\}//g; s/^\(.\{30\}\).\+/\1.../; s/$/\n/' +} + +get_selection() { + [ -n "$1" ] && eval "$CLIP_PASTE_CLIP" || eval "$CLIP_PASTE_PRIM" +} + +clip_menu() { + { formatmenu "$1"; formatmenu "$2"; } | + sed 's/^\s*$//; 1s/^./Primary: &/; 2s/^./Clipboard: &/' | + sed '/^$/d' +} + +lang_menu() { + echo "$TRANS_LANGS" | sed 's/\s\+/\n/g' | sed '/:/!s/^/:/' + echo '[Define]' +} + +choose_next() { + t="$1" + shift + if [ -n "$ALWAYS_COPY" ]; then + echo 'Copy' + else + eval "$DMENU_NEXT" "$@" <<-EOF + Copy: $(formatmenu "$t") + Copy temp file name + View + EOF + fi +} + +save_file() ( + tmp="$(mktemp --tmpdir 'dmenu-translate.XXXXXX')" + echo "$1" > "$tmp" + echo "$tmp" +) + +open_term() { + ${TERMINAL} -e ${PAGER:-'less'} "$(save_file "$1")" +} + +get_text() { + echo "$2" | while IFS= read -r clip; do + [ "$1" = "$clip" ] && { + type="$(echo "$clip" | sed 's/^\(\w\+\):.*/\1/')" + case "$type" in + Primary) echo "$primary" ;; + Clipboard) echo "$clipboard" ;; + esac + exit 10 + } + done + + # If not found, just echo text + [ $? -ne 10 ] && echo "$1" +} + +# Config +load_config + +# Get selections +clipboard="$(get_selection clip)" +primary="$(get_selection)" + +clip_menu="$(clip_menu "$primary" "$clipboard")" + +# Enter text +text="$(printf '%s' "$clip_menu" | eval "$DMENU_TEXT" "$@")" || exit 0 +text="$(get_text "$text" "$clip_menu")" + +# Choose target language +target="$(lang_menu | eval "$DMENU_LANG" "$@")" || exit 0 + +# If Define chosen, define term and exit +[ "$target" = '[Define]' ] && { + dict="$(trans -dictionary "$text")" + open_term "$(trans -dictionary "$text")" + exit 0 +} + +# Translate text +translation="$(trans -b "$target" "$text")" +[ -z "$translation" ] && err 'Failed to translate' + +case "$(choose_next "$translation" "$@")" in + 'View') open_term "$translation"; exit 0 ;; + 'Copy temp file name') output="$(save_file "$translation")" ;; + 'Copy'*) output="$translation" ;; + *) exit 0 ;; +esac + +echo "$output" | eval "$CLIP_COPY" || err 'Failed to copy! Is CLIP_COPY setting set properly?' + +notify-send 'dmenu-translate' 'Translation copied to clipboard!' @@ -2,4 +2,4 @@ dir="$HOME/.obsidian" file="$(ls -l "$dir" | awk '{print $9}' | sed 's/.md//g' | dmenu -l 30)" -batcat "$dir/$file.md" +[ -n "$file" ] && batcat "$dir/$file.md" @@ -0,0 +1,3 @@ +#!/bin/sh + +systemctl suspend @@ -0,0 +1,28 @@ +#!/bin/sh +# +# Write/remove a task to do later. +# +# Select an existing entry to remove it from the file, or type a new entry to +# add it. +# + +file="$HOME/.local/opt/todo" +touch "$file" +height="$(wc -l "$file" | awk '{print $1}')" +prompt="Add/delete a task: " + +cmd=$(dmenu -l "$height" -p "$prompt" "$@" < "$file") +while [ -n "$cmd" ]; do + if grep -q "^$cmd\$" "$file"; then + grep -v "^$cmd\$" "$file" > "$file.$$" + mv "$file.$$" "$file" + height=$(( height - 1 )) + else + echo "$cmd" >> "$file" + height=$(( height + 1 )) + fi + + cmd=$(dmenu -l "$height" -p "$prompt" "$@" < "$file") +done + +exit 0 @@ -0,0 +1,15 @@ +#!/bin/sh + +PATH="$HOME/.config/via:$PATH" + +case "$1" in + -r) # rebuild cache first + via-feed -r | via-menu | via-open + ;; + -ro) # rebuild cache only + via-feed -r >/dev/null + ;; + *) + via-feed | via-menu | via-open + ;; +esac diff --git a/via-feed b/via-feed new file mode 100755 index 0000000..4d1935f --- /dev/null +++ b/via-feed @@ -0,0 +1,12 @@ +#!/bin/bash + +cache="$HOME/.cache/via" + +if [[ "$1" == "-r" ]] || [[ ! -e "$cache" ]]; then + cat "$HOME/.config/via/shortcuts" > "$cache" + cat "$HOME/.config/via/websites" >> "$cache" + find "$HOME" -mindepth 1 \( -name ".*" -o -path "$HOME/cell" -o -path "$HOME/phone/*" \) -prune -o -print | sort >> "$cache" +fi + +wmctrl -xl | sed "s/^[^.]*\.//;s/ \+\S\+ \+/ /;s/^/w /;s/ \+/ /g" +cat "$cache" diff --git a/via-menu b/via-menu new file mode 100755 index 0000000..36f792e --- /dev/null +++ b/via-menu @@ -0,0 +1,3 @@ +#!/bin/bash + +dmenu -p "via" -i -l 30 diff --git a/via-open b/via-open new file mode 100755 index 0000000..6832526 --- /dev/null +++ b/via-open @@ -0,0 +1,56 @@ +#!/bin/bash + +exec &> /dev/null + +while read -r arg; do + # first try matching by filename or pathname + case "${arg,,}" in + w\ *) + target=$(echo "$arg"|cut -d ' ' -f 3-) + wmctrl -a "$target" + ;; + http*) + $BROWSER "$arg" & + ;; + [^/]*) # doesn't start with '/' + sh -c "$arg" + ;; + *.txt) + tabbed -c -r 2 st -w '' -e $EDITOR "$arg" & + # $TERMINAL $EDITOR "$arg" & + ;; + *.pdf | *.epub) + zathura "$arg" & + ;; + *.mp3) + $TERMINAL mpg123 -opulse "$arg" & + ;; + *.od[tsp]|*.doc|*.docx|*.ppt|*.pptx|*.xls|*.xlsx) + libreoffice "$arg" & + ;; + *) + # then try matching by mimetype + mimetype=$(file -Lb --mime-type "$arg") + case "$mimetype" in + text/html) + $BROWSER "$arg" & + ;; + text/* | inode/x-empty | message/rfc822) + tabbed -c -r 2 st -w '' -e $EDITOR "$arg" & + # $TERMINAL $EDITOR "$arg" & + ;; + inode/directory) + cd "$arg" || exit + $TERMINAL & + cd - || exit + ;; + image/*) + sxiv "$arg" & + ;; + *) + exit 1 + ;; + esac + ;; + esac +done |