From 0bd150185551b6d8835d022c15a5f6e832d51113 Mon Sep 17 00:00:00 2001 From: venomade Date: Wed, 11 Feb 2026 11:42:58 +0000 Subject: Asahi Soft reset of dotfiles specific to Asahi, Sway and Neovim. --- .local/bin/battery-screen | 70 ++++++++++++++++++++++++++++++++ .local/bin/lock-screen | 13 ++++++ .local/bin/rofi-notes | 101 ++++++++++++++++++++++++++++++++++++++++++++++ .local/bin/rofi-powermenu | 49 ++++++++++++++++++++++ .local/bin/rofi-ppd | 48 ++++++++++++++++++++++ .local/bin/rofi-translate | 60 +++++++++++++++++++++++++++ .local/bin/rofi-wifimenu | 38 +++++++++++++++++ .local/bin/take-slurpshot | 18 +++++++++ 8 files changed, 397 insertions(+) create mode 100755 .local/bin/battery-screen create mode 100755 .local/bin/lock-screen create mode 100755 .local/bin/rofi-notes create mode 100755 .local/bin/rofi-powermenu create mode 100755 .local/bin/rofi-ppd create mode 100755 .local/bin/rofi-translate create mode 100755 .local/bin/rofi-wifimenu create mode 100755 .local/bin/take-slurpshot (limited to '.local/bin') diff --git a/.local/bin/battery-screen b/.local/bin/battery-screen new file mode 100755 index 0000000..26ac78a --- /dev/null +++ b/.local/bin/battery-screen @@ -0,0 +1,70 @@ +#!/usr/bin/env lua + +local function read(path) + local f = io.open(path) + if not f then return nil end + local v = tonumber(f:read('*l')) + f:close() + return v +end + +local function batterytext() + local base = '/sys/class/power_supply/macsmc-battery/' + + local energy_now = read(base .. 'energy_now') + local energy_full = read(base .. 'energy_full') + local status_f = io.open(base .. 'status') + + if not energy_now or not energy_full or not status_f then + return { { full_text = 'bat ?' } } + end + + local status = status_f:read('*l') + status_f:close() + + local capacity = math.floor(energy_now / energy_full * 100 + 0.5) + + local text_color = '#ffffff' + local battery_symbol = ' ' + + if capacity < 30 then + text_color = '#ed8796' + battery_symbol = '󰁼' + elseif capacity > 70 then + text_color = '#a6da95' + battery_symbol = '󰂁' + else + text_color = '#eed49f' + battery_symbol = '󰁾' + end + + local symbol = ({ + Charging = '󱐋', + Discharging = battery_symbol, + })[status] or ' ' + + return string.format('%s %2d%%', symbol, capacity), text_color +end + +function hexToRgb(hex) + hex = hex:gsub("#", "") + + local r = tonumber(hex:sub(1, 2), 16) + local g = tonumber(hex:sub(3, 4), 16) + local b = tonumber(hex:sub(5, 6), 16) + + return r, g, b +end + +function printHexColor(text, hex) + local r, g, b = hexToRgb(hex) + local colorCode = string.format("\27[38;2;%d;%d;%dm", r, g, b) + local resetCode = "\27[0m" + + print(colorCode .. text .. resetCode) +end + +while true do + printHexColor(batterytext()) + os.execute("sleep 1") -- Wait for 1 second +end diff --git a/.local/bin/lock-screen b/.local/bin/lock-screen new file mode 100755 index 0000000..4307c9a --- /dev/null +++ b/.local/bin/lock-screen @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +if [[ $1 =~ ^[0-9]+$ ]]; then + SLEEP_DURATION=$1 +else + SLEEP_DURATION=10 +fi + +grim /tmp/lockscreen-0.png +magick /tmp/lockscreen-0.png -scale 10% -blur 0x1 -resize 1000% /tmp/lockscreen.png +swaylock -i /tmp/lockscreen.png & +sleep $SLEEP_DURATION +systemctl sleep diff --git a/.local/bin/rofi-notes b/.local/bin/rofi-notes new file mode 100755 index 0000000..876bc66 --- /dev/null +++ b/.local/bin/rofi-notes @@ -0,0 +1,101 @@ +#!/usr/bin/env lua + +local HOME = os.getenv("HOME") +local NOTES = HOME .. "/Documents/Notes" +local TERM = "foot -a=floating_foot" +local EDITOR = "nvim" + +local MODE = arg[1] -- nil | "--delete" | "-d" + +local function rofi(prompt, lines) + local cmd = string.format( + 'printf "%s" | rofi -dmenu -i -p "%s"', + table.concat(lines, "\n"), + prompt + ) + local handle = io.popen(cmd) + local selection = handle:read("*a") + handle:close() + selection = selection:gsub("%s+$", "") + if selection == "" then return nil end + return selection +end + +local function list_notes() + local display = {} + local lookup = {} + + local cmd = string.format('find "%s" -type f', NOTES) + local pipe = assert(io.popen(cmd, "r")) + + for fullPath in pipe:lines() do + local relPath = fullPath:gsub("^" .. NOTES .. "/", "") + local noteName = relPath:gsub("%.[^./]*$", "") + + table.insert(display, noteName) + lookup[noteName] = fullPath + end + + pipe:close() + return display, lookup +end + +local function normalize_path(input) + input = input:gsub("^/", "") + if not input:match("%.md$") then + input = input .. ".md" + end + return NOTES .. "/" .. input +end + +local function ensure_parent_dir(path) + local dir = path:match("(.+)/[^/]+$") + if dir then + os.execute(string.format('mkdir -p "%s"', dir)) + end +end + +local function open_in_nvim(path) + local cmd = string.format( + '%s -e %s "%s"', + TERM, + EDITOR, + path + ) + os.execute(cmd) +end + +local function delete_note(path, name) + local confirm = rofi("Delete " .. name .. "?", { "No", "Yes" }) + if confirm == "Yes" then + os.execute(string.format('rm -- "%s"', path)) + end +end + +-- ---- main ---- + +local notes, paths = list_notes() + +if MODE == "--delete" or MODE == "-d" then + local choice = rofi(" ", notes) + if not choice then os.exit(0) end + + local path = paths[choice] + if path then + delete_note(path, choice) + end + + os.exit(0) +end + +-- default: open / create +local choice = rofi(" ", notes) +if not choice then os.exit(0) end + +local path = paths[choice] +if not path then + path = normalize_path(choice) + ensure_parent_dir(path) +end + +open_in_nvim(path) diff --git a/.local/bin/rofi-powermenu b/.local/bin/rofi-powermenu new file mode 100755 index 0000000..0ff3f9c --- /dev/null +++ b/.local/bin/rofi-powermenu @@ -0,0 +1,49 @@ +#!/usr/bin/env lua + +local function rofi(prompt, lines) + local cmd = string.format( + 'printf "%s" | rofi -dmenu -i -p "%s"', + table.concat(lines, "\n"), + prompt + ) + local handle = io.popen(cmd) + local selection = handle:read("*a") + handle:close() + selection = selection:gsub("%s+$", "") + if selection == "" then return nil end + return selection +end + +local function contains(tbl, val) + for _, v in pairs(tbl) do + if v == val then + return true + end + end + return false +end + +-- TODO: Deduplicate This +local options = { + "Log Out", + "Shutdown", + "Restart" +} + +local option_pair = { + ["Log Out"] = "swaymsg exit", + ["Shutdown"] = "systemctl poweroff", + ["Restart"] = "systemctl reboot" +} + +local choice = rofi("Action:", options) +if (not choice) or (not contains(options,choice)) then os.exit() end + +if choice == "Log Out" then + io.popen(option_pair[choice]) +else + local confirm = rofi("Are you sure?:", {"Yes", "No"}) + if confirm == "Yes" then + io.popen(option_pair[choice]) + end +end diff --git a/.local/bin/rofi-ppd b/.local/bin/rofi-ppd new file mode 100755 index 0000000..5a4f13b --- /dev/null +++ b/.local/bin/rofi-ppd @@ -0,0 +1,48 @@ +#!/usr/bin/env lua + +local function trim(s) + return s:gsub("^%s+", ""):gsub("%s+$", "") +end + +local function rofi(prompt, lines) + local cmd = string.format( + 'printf "%s" | rofi -dmenu -i -p "%s"', + table.concat(lines, "\n"), + prompt + ) + local handle = io.popen(cmd) + local selection = handle:read("*a") + handle:close() + selection = trim(selection or "") + if selection == "" then return nil end + return selection +end + +local modes = {} + +local handle = io.popen('powerprofilesctl list') +local profile_list = handle:read("*a") +handle:close() + +local handle = io.popen('powerprofilesctl get') +local current_profile = trim(handle:read("*a") or "") +handle:close() + +for line in profile_list:gmatch("[^\r\n]+") do + line = trim(line) + local mode = line:match("^%*?%s*([%w%-_]+)%s*:$") + if mode then + if mode == current_profile then + table.insert(modes, "* " .. mode) + else + table.insert(modes, " " .. mode) + end + end +end + +local selected_profile = rofi('󰓅', modes) +if not selected_profile then os.exit() end + +selected_profile = selected_profile:gsub("^%*%s*", ""):gsub("^%s+", "") + +io.popen('powerprofilesctl set ' .. selected_profile) diff --git a/.local/bin/rofi-translate b/.local/bin/rofi-translate new file mode 100755 index 0000000..f71557d --- /dev/null +++ b/.local/bin/rofi-translate @@ -0,0 +1,60 @@ +#!/usr/bin/env lua + +local function rofi(prompt, lines) + local cmd = string.format( + 'printf "%s" | rofi -dmenu -i -p "%s"', + table.concat(lines, "\n"), + prompt + ) + local handle = io.popen(cmd) + local selection = handle:read("*a") + handle:close() + selection = selection:gsub("%s+$", "") + if selection == "" then return nil end + return selection +end + +local function contains(tbl, val) + for _, v in pairs(tbl) do + if v == val then + return true + end + end + return false +end + +local directions = { + "English → Portuguese", + "Portuguese → English" +} + +local choice = rofi("Translate:", directions) +if (not choice) or (not contains(directions,choice)) then os.exit() end + +local lang_pair = { + ["English → Portuguese"] = "en:pt", + ["Portuguese → English"] = "pt:en" +} +local pair = lang_pair[choice] + +local text = rofi("󰗊", { "" }) +if not text then os.exit() end + +local trans_cmd = string.format('trans -b %s "%s"', pair, text:gsub('"', '\\"')) +local trans_handle = io.popen(trans_cmd) +local translation = trans_handle:read("*a") +trans_handle:close() +translation = translation:gsub("%s+$", "") + +if translation == "" then + translation = "(no translation returned)" +else + io.popen("wl-copy " .. translation) +end + +local notify_cmd = string.format( + 'notify-send -- "Translation (%s)" "%s"', + choice, + translation:gsub('"', '\\"') +) +os.execute(notify_cmd) diff --git a/.local/bin/rofi-wifimenu b/.local/bin/rofi-wifimenu new file mode 100755 index 0000000..fb45671 --- /dev/null +++ b/.local/bin/rofi-wifimenu @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +notify-send "Getting list of available Wi-Fi networks..." +# Get a list of available wifi connections and morph it into a nice-looking list +wifi_list=$(nmcli --fields "SECURITY,SSID" device wifi list | sed 1d | sed 's/ */ /g' | sed -E "s/WPA*.?\S/ /g" | sed "s/^--/ /g" | sed "s/ //g" | sed "/--/d") + +connected=$(nmcli -fields WIFI g) +if [[ "$connected" =~ "enabled" ]]; then + toggle="󰖪 Disable Wi-Fi" +elif [[ "$connected" =~ "disabled" ]]; then + toggle="󰖩 Enable Wi-Fi" +fi + +# Use rofi to select wifi network +chosen_network=$(echo -e "$toggle\n$wifi_list" | uniq -u | rofi -dmenu -i -selected-row 1 -p "Wi-Fi SSID: " ) +# Get name of connection +read -r chosen_id <<< "${chosen_network:3}" + +if [ "$chosen_network" = "" ]; then + exit +elif [ "$chosen_network" = "󰖩 Enable Wi-Fi" ]; then + nmcli radio wifi on +elif [ "$chosen_network" = "󰖪 Disable Wi-Fi" ]; then + nmcli radio wifi off +else + # Message to show when connection is activated successfully + success_message="You are now connected to the Wi-Fi network \"$chosen_id\"." + # Get saved connections + saved_connections=$(nmcli -g NAME connection) + if [[ $(echo "$saved_connections" | grep -w "$chosen_id") = "$chosen_id" ]]; then + nmcli connection up id "$chosen_id" | grep "successfully" && notify-send "Connection Established" "$success_message" + else + if [[ "$chosen_network" =~ "" ]]; then + wifi_password=$(rofi -dmenu -p "Password: " ) + fi + nmcli device wifi connect "$chosen_id" password "$wifi_password" | grep "successfully" && notify-send "Connection Established" "$success_message" + fi +fi diff --git a/.local/bin/take-slurpshot b/.local/bin/take-slurpshot new file mode 100755 index 0000000..f30fabe --- /dev/null +++ b/.local/bin/take-slurpshot @@ -0,0 +1,18 @@ +#!/bin/bash + +# Generate base filename with timestamp +base_filename=$(date +"%m-%d-%Y_%H-%M-%S") +extension=".png" + +# Initialize full filename +filename="${base_filename}${extension}" +counter=1 + +# Check if file exists and append incremental suffix if needed +while [[ -e "$filename" ]]; do + filename="${base_filename}-${counter}${extension}" + ((counter++)) +done + +# Output the available filename +grim -g "$(slurp)" "$HOME/Pictures/Screenshots/$filename" -- cgit 1.4.1-2-gfad0