Krolyxon
Commit b17a3d9

Branches

Refs →

aurorab17a3d9

add define_word script

Author
krolxon
Date
2025-10-10 21:08 +0530
Parent
bfcfc9f
Commit
b17a3d98f755b0d2dcf5035d79ce771b4ecd258e

+41 −4

3 files changed

  1. M .local/bin/bcn +1 −1
  2. A .local/bin/define_word +37 −0
  3. M .local/bin/movie +3 −3
M .local/bin/bcn View
@@ -9,7 +9,7 @@ if [[ $device_amount = 1 ]]; then
99 MAC=$(bluetoothctl devices | awk {'print $2'})
1010 [ -z $MAC ] && MAC=NoDeviceFound # Prevents accidental disconnect error
1111 else
12− select=$(bluetoothctl devices | awk {'print $3'} | rofi -dmenu -l 10 -fn Monospace-15)
12+ select=$(bluetoothctl devices | awk {'print $3'} | fuzzel --dmenu -l 10 -fn Monospace-15)
1313 MAC=$(bluetoothctl devices | grep $select | awk {'print $2'})
1414 [ -z $MAC ] && MAC=NoDeviceFound # Prevents accidental disconnect error
1515 fi
A .local/bin/define_word View
@@ -0,0 +1,37 @@
1+#!/usr/bin/env bash
2+
3+word=${1:-$(xclip -o -selection primary 2>/dev/null || wl-paste 2>/dev/null)}
4+
5+# Check for empty word or special characters
6+[[ -z "$word" || "$word" =~ [\/] ]] && notify-send -h string:bgcolor:#bf616a -t 3000 "Invalid input." && exit 0
7+
8+query=$(curl -s --connect-timeout 5 --max-time 10 "https://api.dictionaryapi.dev/api/v2/entries/en_US/$word")
9+
10+# Check for connection error (curl exit status stored in $?)
11+[ $? -ne 0 ] && notify-send -h string:bgcolor:#bf616a -t 3000 "Connection error." && exit 1
12+
13+# Check for invalid word response
14+[[ "$query" == *"No Definitions Found"* ]] && notify-send -h string:bgcolor:#bf616a -t 3000 "Invalid word." && exit 0
15+
16+# Show only first 3 definitions
17+def=$(echo "$query" | jq -r '[.[].meanings[] | {pos: .partOfSpeech, def: .definitions[].definition}] | .[:3].[] | "\n\(.pos). \(.def)"')
18+
19+# Requires a notification daemon to be installed
20+notify-send -t 60000 "$word -" "$def"
21+
22+
23+### MORE OPTIONS :)
24+
25+# Show first definition for each part of speech (thanks @morgengabe1 on youtube)
26+# def=$(echo "$query" | jq -r '.[0].meanings[] | "\(.partOfSpeech): \(.definitions[0].definition)\n"')
27+
28+# Show all definitions
29+# def=$(echo "$query" | jq -r '.[].meanings[] | "\n\(.partOfSpeech). \(.definitions[].definition)"')
30+
31+# Regex + grep for just definition, if anyone prefers that to jq
32+# def=$(grep -Po '"definition":"\K(.*?)(?=")' <<< "$query")
33+
34+# bold=$(tput bold) # Print text bold with echo, for visual clarity
35+# normal=$(tput sgr0) # Reset text to normal
36+# echo "${bold}Definition of $word"
37+# echo "${normal}$def"
M .local/bin/movie View
@@ -2,11 +2,11 @@
22
33
44 if [ -t 0 ]; then
5− filename="$(find ~/media/movies/ -type f -regex ".*\.\(mkv\|mp4\|mpeg\|avi\|mov\|webm\)" -printf "%f\n" | sort | fzf)"
5+ filename="$(find ~/remote/movies/ -type f -regex ".*\.\(mkv\|mp4\|mpeg\|avi\|mov\|webm\)" -printf "%f\n" | sort | fzf)"
66 else
7− filename="$(find ~/media/movies/ -type f -regex ".*\.\(mkv\|mp4\|mpeg\|avi\|mov\|webm\)" -printf "%f\n" | sort | fuzzel -d -l 25)"
7+ filename="$(find ~/remote/movies/ -type f -regex ".*\.\(mkv\|mp4\|mpeg\|avi\|mov\|webm\)" -printf "%f\n" | sort | fuzzel -d -l 25)"
88 fi
99
10−filepath="$(find ~/media/movies/ -type f -regex ".*\.\(mkv\|mp4\|mpeg\|avi\|mov\|webm\)")"
10+filepath="$(find ~/remote/movies/ -type f -regex ".*\.\(mkv\|mp4\|mpeg\|avi\|mov\|webm\)")"
1111 mpv "$(grep "$filename" <<< "$filepath")"
1212