aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkrolxon <krolyxon@tutanota.com>2025-10-10 21:08:40 +0530
committerkrolxon <krolyxon@tutanota.com>2025-10-10 21:08:40 +0530
commitb17a3d98f755b0d2dcf5035d79ce771b4ecd258e (patch)
treecd80514ced7e58d275b42d42d29d25b721f5442f
parentbfcfc9f04da5757b1e5e44eac0fb9e57fe41bf26 (diff)
add define_word script
-rwxr-xr-x.local/bin/bcn2
-rwxr-xr-x.local/bin/define_word37
-rwxr-xr-x.local/bin/movie6
3 files changed, 41 insertions, 4 deletions
diff --git a/.local/bin/bcn b/.local/bin/bcn
index 1c64085..b87e2ab 100755
--- a/.local/bin/bcn
+++ b/.local/bin/bcn
@@ -9,7 +9,7 @@ if [[ $device_amount = 1 ]]; then
MAC=$(bluetoothctl devices | awk {'print $2'})
[ -z $MAC ] && MAC=NoDeviceFound # Prevents accidental disconnect error
else
- select=$(bluetoothctl devices | awk {'print $3'} | rofi -dmenu -l 10 -fn Monospace-15)
+ select=$(bluetoothctl devices | awk {'print $3'} | fuzzel --dmenu -l 10 -fn Monospace-15)
MAC=$(bluetoothctl devices | grep $select | awk {'print $2'})
[ -z $MAC ] && MAC=NoDeviceFound # Prevents accidental disconnect error
fi
diff --git a/.local/bin/define_word b/.local/bin/define_word
new file mode 100755
index 0000000..5c1105a
--- /dev/null
+++ b/.local/bin/define_word
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+
+word=${1:-$(xclip -o -selection primary 2>/dev/null || wl-paste 2>/dev/null)}
+
+# Check for empty word or special characters
+[[ -z "$word" || "$word" =~ [\/] ]] && notify-send -h string:bgcolor:#bf616a -t 3000 "Invalid input." && exit 0
+
+query=$(curl -s --connect-timeout 5 --max-time 10 "https://api.dictionaryapi.dev/api/v2/entries/en_US/$word")
+
+# Check for connection error (curl exit status stored in $?)
+[ $? -ne 0 ] && notify-send -h string:bgcolor:#bf616a -t 3000 "Connection error." && exit 1
+
+# Check for invalid word response
+[[ "$query" == *"No Definitions Found"* ]] && notify-send -h string:bgcolor:#bf616a -t 3000 "Invalid word." && exit 0
+
+# Show only first 3 definitions
+def=$(echo "$query" | jq -r '[.[].meanings[] | {pos: .partOfSpeech, def: .definitions[].definition}] | .[:3].[] | "\n\(.pos). \(.def)"')
+
+# Requires a notification daemon to be installed
+notify-send -t 60000 "$word -" "$def"
+
+
+### MORE OPTIONS :)
+
+# Show first definition for each part of speech (thanks @morgengabe1 on youtube)
+# def=$(echo "$query" | jq -r '.[0].meanings[] | "\(.partOfSpeech): \(.definitions[0].definition)\n"')
+
+# Show all definitions
+# def=$(echo "$query" | jq -r '.[].meanings[] | "\n\(.partOfSpeech). \(.definitions[].definition)"')
+
+# Regex + grep for just definition, if anyone prefers that to jq
+# def=$(grep -Po '"definition":"\K(.*?)(?=")' <<< "$query")
+
+# bold=$(tput bold) # Print text bold with echo, for visual clarity
+# normal=$(tput sgr0) # Reset text to normal
+# echo "${bold}Definition of $word"
+# echo "${normal}$def"
diff --git a/.local/bin/movie b/.local/bin/movie
index b56828f..1cee6f5 100755
--- a/.local/bin/movie
+++ b/.local/bin/movie
@@ -2,11 +2,11 @@
if [ -t 0 ]; then
- filename="$(find ~/media/movies/ -type f -regex ".*\.\(mkv\|mp4\|mpeg\|avi\|mov\|webm\)" -printf "%f\n" | sort | fzf)"
+ filename="$(find ~/remote/movies/ -type f -regex ".*\.\(mkv\|mp4\|mpeg\|avi\|mov\|webm\)" -printf "%f\n" | sort | fzf)"
else
- filename="$(find ~/media/movies/ -type f -regex ".*\.\(mkv\|mp4\|mpeg\|avi\|mov\|webm\)" -printf "%f\n" | sort | fuzzel -d -l 25)"
+ filename="$(find ~/remote/movies/ -type f -regex ".*\.\(mkv\|mp4\|mpeg\|avi\|mov\|webm\)" -printf "%f\n" | sort | fuzzel -d -l 25)"
fi
-filepath="$(find ~/media/movies/ -type f -regex ".*\.\(mkv\|mp4\|mpeg\|avi\|mov\|webm\)")"
+filepath="$(find ~/remote/movies/ -type f -regex ".*\.\(mkv\|mp4\|mpeg\|avi\|mov\|webm\)")"
mpv "$(grep "$filename" <<< "$filepath")"