From a5a501116087587e043d9c682de28f5297059c55 Mon Sep 17 00:00:00 2001 From: filip <“filip.rabiega@gmail.com”> Date: Wed, 12 Nov 2025 09:54:05 +0100 Subject: no message --- aptup | 5 --- dtrans | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fz | 3 ++ fz-feed | 12 +++++ late | 150 ------------------------------------------------------------- mansplain | 2 +- newsup | 3 ++ notesplain | 2 +- volume | 8 +++- wrocwttr | 10 +++++ 10 files changed, 187 insertions(+), 158 deletions(-) delete mode 100755 aptup create mode 100755 dtrans create mode 100755 fz create mode 100755 fz-feed delete mode 100755 late create mode 100755 wrocwttr diff --git a/aptup b/aptup deleted file mode 100755 index 6d1398e..0000000 --- a/aptup +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -/usr/bin/notify-send "Updating packages..." -apt -y update && apt -y upgrade -/usr/bin/notify-send "Packages updated." diff --git a/dtrans b/dtrans new file mode 100755 index 0000000..5f4ced1 --- /dev/null +++ b/dtrans @@ -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 $old_config_file, which is no longer supported. Please move your settings to a new file at $config_file 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!' diff --git a/fz b/fz new file mode 100755 index 0000000..ea35024 --- /dev/null +++ b/fz @@ -0,0 +1,3 @@ +#!/bin/bash + +fz-feed | dmenu -p "fz" -i -l 15 | xargs -r zathura diff --git a/fz-feed b/fz-feed new file mode 100755 index 0000000..988d1ba --- /dev/null +++ b/fz-feed @@ -0,0 +1,12 @@ +#!/bin/sh + +cache="$HOME/.cache/fz" + +if [ "$1" = "-r" ] || [ ! -e "$cache" ]; then + find "$HOME" -mindepth 1 \( -name ".*" -o -path "$HOME/cell" -o -path "$HOME/phone/*" \) -prune -o -print | \ + sed '/\.pdf$/!d' | sort > "$cache" + + notify-send "fz cache updated." +fi + +cat "$cache" diff --git a/late b/late deleted file mode 100755 index 5f4ced1..0000000 --- a/late +++ /dev/null @@ -1,150 +0,0 @@ -#!/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 $old_config_file, which is no longer supported. Please move your settings to a new file at $config_file 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!' diff --git a/mansplain b/mansplain index 625528e..6c7973b 100755 --- a/mansplain +++ b/mansplain @@ -1,4 +1,4 @@ #!/bin/sh -arg="$( man -k . | dmenu -l 30 | awk '{print $1}')" +arg="$( man -k . | dmenu -l 15 | awk '{print $1}')" [ -n "$arg" ] && man -Tpdf "$arg" | zathura - diff --git a/newsup b/newsup index 93ecbb3..42e90fd 100755 --- a/newsup +++ b/newsup @@ -1,5 +1,8 @@ #!/bin/sh +export DISPLAY=:0.0 +export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus + /usr/bin/notify-send "Updating RSS feeds..." pgrep -f newsboat$ && /usr/bin/xdotool key --window "$(/usr/bin/xdotool search --name "^newsboat$")" R && exit diff --git a/notesplain b/notesplain index 3249258..8136cec 100755 --- a/notesplain +++ b/notesplain @@ -1,7 +1,7 @@ #!/bin/sh dir="$OBSIDIAN_HOME" -file="$(ls -1 "$dir" | sed 's/\.md$//' | dmenu -l 30 -p 'Select note:')" +file="$(ls -1 "$dir" | sed 's/\.md$//' | dmenu -l 15 -p 'Select note:')" if [ -n "$file" ]; then tmpfile="$(mktemp /tmp/"$file"_XXXXXXXX.pdf)" diff --git a/volume b/volume index b40ecf1..3da8d8f 100755 --- a/volume +++ b/volume @@ -1,3 +1,9 @@ #!/bin/sh +# TODO: see if pulseaudio is running -pactl set-sink-volume @DEFAULT_SINK@ "$1" +case "$1" in + up) pactl set-sink-volume @DEFAULT_SINK@ "+5%" ;; + down) pactl set-sink-volume @DEFAULT_SINK@ "-5%" ;; + mute) pactl set-sink-mute @DEFAULT_SINK@ toggle ;; + *) pactl set-sink-volume @DEFAULT_SINK@ "$1" ;; +esac diff --git a/wrocwttr b/wrocwttr new file mode 100755 index 0000000..b1bb3af --- /dev/null +++ b/wrocwttr @@ -0,0 +1,10 @@ +#!/bin/sh + +export DISPLAY=:0.0 +export HOME=/home/filipek + +temp=$(curl wttr.in/Wrocław?format=1 | awk '{print $2}') +file="$HOME/.cache/weather/wroc.txt" + +echo "$temp" > "$file" +notify-send "Temperature updated." -- cgit v1.2.3