mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
feat: Moves local scripts directory. Handles systemd configurations.
This commit is contained in:
8
env/.config/systemd/user/battery-monitor.service
vendored
Normal file
8
env/.config/systemd/user/battery-monitor.service
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=Battery Monitor Service
|
||||
After=graphical-session.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=%h/.local/scripts/battery-monitor
|
||||
Environment=DISPLAY=:0
|
||||
11
env/.config/systemd/user/battery-monitor.timer
vendored
Normal file
11
env/.config/systemd/user/battery-monitor.timer
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Battery Monitor Timer
|
||||
Requires=battery-monitor.service
|
||||
|
||||
[Timer]
|
||||
OnBootSec=1min
|
||||
OnUnitActiveSec=30sec
|
||||
AccuracySec=10sec
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
11
env/.config/systemd/user/logout-task.service
vendored
Normal file
11
env/.config/systemd/user/logout-task.service
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Clear clipboard history at logout
|
||||
DefaultDependencies=no
|
||||
Before=exit.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=%h/.local/scripts/clear-clipboard-history
|
||||
|
||||
[Install]
|
||||
WantedBy=exit.target
|
||||
129
env/.local/scripts/ask-gpt
vendored
Executable file
129
env/.local/scripts/ask-gpt
vendored
Executable file
@@ -0,0 +1,129 @@
|
||||
#!/bin/zsh
|
||||
#
|
||||
# Ask chat-gpt a question and view the output.
|
||||
|
||||
local api_key="${OPENAI_API_KEY}"
|
||||
local debug="${DEBUG}"
|
||||
local outputFile="/tmp/output.json"
|
||||
|
||||
function usage() {
|
||||
cat << EOF
|
||||
|
||||
Ask chat-gpt a question and view the output.
|
||||
|
||||
Example usage:
|
||||
|
||||
ask-gpt 'Who are you?'
|
||||
|
||||
# Send output to a file:
|
||||
ask-gpt --print 'Who are you' > /tmp/gpt.md
|
||||
|
||||
Usage: ask-gpt [-k <key>] [-m <model>] [-p] [-j] [-h] question
|
||||
|
||||
Options:
|
||||
-k | --key : Use api key (default: environment variable 'OPENAI_API_KEY')
|
||||
-m | --model: Specify the chat-gpt model (default is 'gpt-4o-mini')
|
||||
-j | --json: Print the full json output to stdout.
|
||||
-p | --print: Print the output to stdout in markdown format.
|
||||
-h | --help: Show usage.
|
||||
|
||||
Include debug output:
|
||||
|
||||
DEBUG=1 ask-gpt 'Who are you?'
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
######################### Helpers #########################
|
||||
|
||||
function debug_print {
|
||||
if [ ! -z "$debug" ]; then
|
||||
echo "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
function makeGptInput {
|
||||
echo $(jq --null-input \
|
||||
--arg model "$1" \
|
||||
--arg question "$2" \
|
||||
'{
|
||||
"model": $model,
|
||||
"messages": [
|
||||
{ "role": "system", "content": "You are such a helpful assistant!" },
|
||||
{ "role": "developer", "content": "You message data is escaped properly to parse as JSON, including escaping newline characters." },
|
||||
{ "role": "user", "content": $question }
|
||||
]
|
||||
}')
|
||||
}
|
||||
|
||||
function getGptOutput {
|
||||
echo "$1" | jq -r '.choices[].message.content'
|
||||
}
|
||||
|
||||
function askGpt {
|
||||
local key=$1
|
||||
local input=$2
|
||||
|
||||
echo $(curl "https://api.openai.com/v1/chat/completions" \
|
||||
-sS \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $key" \
|
||||
-d "$input")
|
||||
}
|
||||
|
||||
######################### MAIN #########################
|
||||
zparseopts -D -E -F -- \
|
||||
{h,-help}=help \
|
||||
{k,-key}:=key \
|
||||
{m,-model}=model \
|
||||
{j,-json}=json \
|
||||
{p,-print}=printOutput
|
||||
|
||||
# Check if help was specified and show usage.
|
||||
[ ! -z "$help" ] && usage && exit 0
|
||||
|
||||
local question="$1"
|
||||
# Ensure there is a question / first argument.
|
||||
[ -z "$question" ] && print "No question found." && usage && exit 1
|
||||
|
||||
# parse the api key.
|
||||
if [ ! -z "$key" ]; then
|
||||
api_key="${key[-1]}"
|
||||
debug_print "Using custom passed in key."
|
||||
fi
|
||||
|
||||
# Fail if we did not find an api key.
|
||||
[ -z "$api_key" ] && echo "No api key found." && usage && exit 1
|
||||
|
||||
# Set default model if not specified.
|
||||
if [ -z "$model" ]; then
|
||||
model="gpt-4o-mini"
|
||||
fi
|
||||
debug_print "Model: $model"
|
||||
|
||||
# Generate the input for chat-gpt.
|
||||
local input="$(makeGptInput $model $question)"
|
||||
debug_print "Input: $input"
|
||||
|
||||
# Get the chat-gpt output.
|
||||
local output="$(askGpt $api_key $input)"
|
||||
|
||||
# TODO: Remove.
|
||||
echo "$output" > "$outputFile"
|
||||
|
||||
debug_print "Full ouptput: $(echo $output | jq '.')"
|
||||
|
||||
# If json option is specified, then send full output to stdout and exit.
|
||||
[ ! -z "$json" ] && (echo "$output" | jq '.') && exit 0
|
||||
|
||||
# parse the output message.
|
||||
local parsedOutput="$(getGptOutput $output)"
|
||||
|
||||
echo "$parsedOutput"
|
||||
|
||||
# Show the output based on options passed in.
|
||||
# if [ -z "$printOutput" ]; then
|
||||
# echo "# $question\n$parsedOutput" | gum format | gum pager
|
||||
# else
|
||||
# echo "# $question\n$parsedOutput" | gum format
|
||||
# fi
|
||||
32
env/.local/scripts/battery-monitor
vendored
Executable file
32
env/.local/scripts/battery-monitor
vendored
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/zsh
|
||||
|
||||
# Used with the systemd battery monitor service and timer to alert
|
||||
# when the battery has dropped below the threshold and is not currently
|
||||
# charging.
|
||||
|
||||
THRESHOLD=20 # Notify when below 20%
|
||||
NOTIFICATION_FLAG="/run/user/${UID}/user_battery_notified"
|
||||
|
||||
function get-battery-percentage() {
|
||||
local battery=$(upower --battery | grep percentage)
|
||||
echo "${battery//[^0-9]/}"
|
||||
}
|
||||
|
||||
function send-battery-alert() {
|
||||
notify-send -u critical \
|
||||
"Recharge battery!" "Batttery is down to ${1}" \
|
||||
-i battery-caution \
|
||||
-t 30000
|
||||
}
|
||||
|
||||
battery_percentage=$(get-battery-percentage)
|
||||
battery_state=$(upower --battery | grep -E state | awk '{print $2}')
|
||||
|
||||
if [[ "$battery_state" == "discharging" && "$battery_percentage" -le "$THRESHOLD" ]]; then
|
||||
if [ ! -f "$NOTIFICATION_FLAG" ]; then
|
||||
send-battery-alert "$battery_percentage"
|
||||
touch "$NOTIFICATION_FLAG"
|
||||
fi
|
||||
else
|
||||
rm -f "$NOTIFICATION_FLAG"
|
||||
fi
|
||||
8
env/.local/scripts/clear-clipboard-history
vendored
Executable file
8
env/.local/scripts/clear-clipboard-history
vendored
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
#wl-copy --clear >/dev/null 2>&1 && \
|
||||
if [ -n "$WAYLAND_DISPLAY" ]; then
|
||||
wl-copy --clear
|
||||
fi
|
||||
|
||||
rm ~/.local/share/clipse/clipboard_history.json >/dev/null 2>&1
|
||||
5
env/.local/scripts/close-all-windows
vendored
Executable file
5
env/.local/scripts/close-all-windows
vendored
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
hyprctl clients -j | \
|
||||
jq '.[] | .address' | \
|
||||
xargs -I{} hyprctl dispatch closewindow address:{}
|
||||
11
env/.local/scripts/haasd
vendored
Executable file
11
env/.local/scripts/haasd
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Creates a new `zet` inside the $HAAS/documents repository
|
||||
|
||||
_main() {
|
||||
(ZETDIR="$HAAS/documents" eval zet "$@")
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
11
env/.local/scripts/haasp
vendored
Executable file
11
env/.local/scripts/haasp
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Creates a new `zet` inside the House Call Pro `Zettlekasten`
|
||||
|
||||
_main() {
|
||||
(ZETDIR="$HAAS/processes" eval zet "$@")
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
12
env/.local/scripts/haasz
vendored
Executable file
12
env/.local/scripts/haasz
vendored
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
# Uses the `zet` command setting the directory to the
|
||||
# Housh As A System zet repository.
|
||||
|
||||
main() {
|
||||
(ZETDIR="$HAASZET" eval zet "$@")
|
||||
}
|
||||
|
||||
main "$@"
|
||||
11
env/.local/scripts/hcpn
vendored
Executable file
11
env/.local/scripts/hcpn
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Creates a new `zet` inside the House Call Pro `Zettlekasten`
|
||||
|
||||
_main() {
|
||||
(ZETDIR="$HCP_NOTES" eval zet "$@")
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
11
env/.local/scripts/hxzet
vendored
Executable file
11
env/.local/scripts/hxzet
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Creates a new `zet` inside the House Call Pro `Zettlekasten`
|
||||
|
||||
_main() {
|
||||
(ZETDIR="$HXZET" eval zet "$@")
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
151
env/.local/scripts/install-webapp
vendored
Executable file
151
env/.local/scripts/install-webapp
vendored
Executable file
@@ -0,0 +1,151 @@
|
||||
#!/bin/zsh
|
||||
|
||||
# Adapted from https://github.com/basecamp/omarchy/tree/master?tab=readme-ov-file
|
||||
|
||||
function usage() {
|
||||
cat <<EOF
|
||||
Generates a '.desktop' file for a web application, so that it
|
||||
can act as a stand alone application and launched from an application
|
||||
launcher.
|
||||
|
||||
USAGE: install-webapp [-n <name>] [-u <url>] [-i <icon>] [-e <exec-cmd>] [-m <mime-types>] [-h] [args...]
|
||||
|
||||
OPTIONS:
|
||||
-n | --name: The name of the application.
|
||||
-u | --url: The url used to launch the application.
|
||||
-i | --icon: The icon for the application.
|
||||
-e | --exec: Custom execution command (optional).
|
||||
-m | --mime-types: MIME-types for the application (optional).
|
||||
-h | --help: Show usage information.
|
||||
|
||||
EXAMPLES:
|
||||
|
||||
If no options or arguments are supplied, then it will start an interactive session that prompts for the
|
||||
values.
|
||||
|
||||
$ install-webapp
|
||||
|
||||
Calling the app with named arguments:
|
||||
|
||||
$ install-webapp \\
|
||||
--name "My Awesome App" \\
|
||||
--url "https://awesome.com" \\
|
||||
--icon "https://awesome.com/assets/icon.png"
|
||||
|
||||
It is also possible to use only positional arguments with out their key. They can be passed in the order as
|
||||
they're listed.
|
||||
|
||||
$ install-webapp "My Awesome App" \\
|
||||
"https://awesome.com" \\
|
||||
"https://awesome.com/assets/icon.png"
|
||||
|
||||
NOTES:
|
||||
|
||||
The icon option can either be a url where we will download a png from or a local file. Local files
|
||||
can either be the full path to the file or a file name of an icon located in '~/.local/share/applications/icons/'.
|
||||
|
||||
Interactive sessions do not give the option to use a custom execution command or supply the
|
||||
MIME types, which are less frequently used options.
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
declare -a app_name
|
||||
declare -a app_url
|
||||
declare -a icon_ref
|
||||
declare -a custom_exec # Optional custom exec command
|
||||
declare -a mime_types # Optional mime types
|
||||
declare -a help_flag
|
||||
declare INTERACTIVE_MODE=false
|
||||
|
||||
zparseopts -D -F -K -- \
|
||||
{n,-name}:=app_name \
|
||||
{u,-url}:=app_url \
|
||||
{i,-icon}:=icon_ref \
|
||||
{e,-exec}:=custom_exec \
|
||||
{m,-mime-types}:=mime_types \
|
||||
{h,-help}=help_flag
|
||||
|
||||
[ ${#help_flag[@]} -gt 0 ] && usage && exit 0
|
||||
|
||||
# If passed in as positional arguments, without flags.
|
||||
[ -n "$1" ] && app_name+=("$1")
|
||||
[ -n "$2" ] && app_url+=("$2")
|
||||
[ -n "$3" ] && icon_ref+=("$3")
|
||||
[ -n "$4" ] && custom_exec+=("$4")
|
||||
[ -n "$5" ] && mime_types+=("$5")
|
||||
|
||||
# Check if proper arguments were passed in. Start interactive mode if not.
|
||||
if [[ -z "$app_name[-1]" || -z "$app_url[-1]" || -z "$icon_ref[-1]" ]]; then
|
||||
echo -e "\e[32mLet's create a new web app you can start with the app launcher.\n\e[0m"
|
||||
app_name+=($(gum input --prompt "Name> " --placeholder "My favorite web app"))
|
||||
app_url+=($(gum input --prompt "URL> " --placeholder "https://example.com"))
|
||||
icon_ref+=($(gum input --prompt "Icon URL> " --placeholder "See https://dashboardicons.com (must use PNG!)"))
|
||||
INTERACTIVE_MODE=true
|
||||
else
|
||||
INTERACTIVE_MODE=false
|
||||
fi
|
||||
|
||||
# Ensure valid execution
|
||||
if [[ -z "$app_name[-1]" || -z "$app_url[-1]" || -z "$icon_ref[-1]" ]]; then
|
||||
echo "You must set app name, app URL, and icon URL!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
APP_NAME=$app_name[-1]
|
||||
APP_URL=$app_url[-1]
|
||||
ICON_REF=$icon_ref[-1]
|
||||
CUSTOM_EXEC=$custom_exec[-1]
|
||||
MIME_TYPES=$mime_types[-1]
|
||||
|
||||
# Refer to local icon or fetch remotely from URL
|
||||
ICON_DIR="$HOME/.local/share/applications/icons"
|
||||
if [[ $ICON_REF == https://* ]]; then
|
||||
ICON_PATH="$ICON_DIR/$APP_NAME.png"
|
||||
if curl -sL -o "$ICON_PATH" "$ICON_REF"; then
|
||||
ICON_PATH="$ICON_DIR/$APP_NAME.png"
|
||||
else
|
||||
echo "Error: Failed to download icon."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# Check if the icon path is a file.
|
||||
if [ -f $ICON_REF ]; then
|
||||
ICON_PATH=$ICON_REF
|
||||
else
|
||||
ICON_PATH="$ICON_DIR/$ICON_REF"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Use custom exec if provided, otherwise default behavior
|
||||
if [[ -n $CUSTOM_EXEC ]]; then
|
||||
EXEC_COMMAND="$CUSTOM_EXEC"
|
||||
else
|
||||
EXEC_COMMAND="$HOME/.local/bin/launch-webapp $APP_URL"
|
||||
fi
|
||||
|
||||
# Create application .desktop file
|
||||
DESKTOP_FILE="$HOME/.local/share/applications/$APP_NAME.desktop"
|
||||
|
||||
cat >"$DESKTOP_FILE" <<EOF
|
||||
[Desktop Entry]
|
||||
Version=1.0
|
||||
Name=$APP_NAME
|
||||
Comment=$APP_NAME
|
||||
Exec=$EXEC_COMMAND
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Icon=$ICON_PATH
|
||||
StartupNotify=true
|
||||
EOF
|
||||
|
||||
# Add mime types if provided
|
||||
if [[ -n $MIME_TYPES ]]; then
|
||||
echo "MimeType=$MIME_TYPES" >>"$DESKTOP_FILE"
|
||||
fi
|
||||
|
||||
chmod +x "$DESKTOP_FILE"
|
||||
|
||||
if [[ $INTERACTIVE_MODE == true ]]; then
|
||||
echo -e "You can now find $APP_NAME using the app launcher (SUPER + SPACE)\n"
|
||||
fi
|
||||
4
env/.local/scripts/isosec
vendored
Executable file
4
env/.local/scripts/isosec
vendored
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
date -u '+%Y%m%d%H%M%S'
|
||||
|
||||
7
env/.local/scripts/launch-webapp
vendored
Executable file
7
env/.local/scripts/launch-webapp
vendored
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Adapted from https://github.com/basecamp/omarchy/tree/master?tab=readme-ov-file
|
||||
#
|
||||
browser="chromium.desktop"
|
||||
|
||||
exec setsid uwsm app -- $(sed -n 's/^Exec=\([^ ]*\).*/\1/p' {~/.local,~/.nix-profile,/usr}/share/applications/$browser 2>/dev/null | head -1) --app="$1" "${@:2}"
|
||||
66
env/.local/scripts/mhlink
vendored
Executable file
66
env/.local/scripts/mhlink
vendored
Executable file
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
# Generates a link to my website / blog.
|
||||
#
|
||||
# Use the -l | --last option to generate a link based on the most
|
||||
# recent page-bundle created (this does not work if the post has been
|
||||
# sitting around / worked on for a bit).
|
||||
#
|
||||
# If no option is passed in then it will open an fzf (fuzzy search)
|
||||
# from the directories.
|
||||
#
|
||||
# Use the --local option to generate a link to a version running on localhost.
|
||||
#
|
||||
# A general usage to generate a link and copy it to the clipboard:
|
||||
#
|
||||
# `$ mhlink --last | pbcopy`
|
||||
#
|
||||
#
|
||||
|
||||
#################### Options ####################
|
||||
lastOpt=
|
||||
localOpt=
|
||||
|
||||
zparseopts -- \
|
||||
{l,-last}=lastOpt \
|
||||
-local=localOpt
|
||||
|
||||
#################### Main ####################
|
||||
|
||||
if [ -d "$GHREPOS/mhoush.com" ]; then
|
||||
root="$$GHREPOS/mhoush.com"
|
||||
else
|
||||
root="$HOME/projects/mhoush.com"
|
||||
fi
|
||||
|
||||
postsPath="$root/content/posts"
|
||||
|
||||
# Abort early if the post path does not exist.
|
||||
[ ! -d $postsPath ] \
|
||||
&& echo "Could not find posts directory" \
|
||||
&& exit 1
|
||||
|
||||
# Get's all the directories / page-bundles.
|
||||
posts=$(find "$postsPath" -mindepth 1 -maxdepth 1 -type d -print0 | \
|
||||
xargs -0 stat -f"%m %Sm %N" | \
|
||||
sort -rn)
|
||||
|
||||
# Use the last directory or choose from a list.
|
||||
[ -n "$lastOpt" ] \
|
||||
&& choice=$(echo $posts | tr '\n' ' ' | cut -w -f6) \
|
||||
|| choice=$(echo $posts | fzf)
|
||||
|
||||
# Delete everything before the last /
|
||||
choice="${choice##*/}"
|
||||
|
||||
# Exit if a choice was not made / found.
|
||||
[ -z $choice ] \
|
||||
&& echo "No selection made." \
|
||||
&& exit 1
|
||||
|
||||
# Set the prefix / website according to the options.
|
||||
[ -n "$localOpt" ] \
|
||||
&& prefix="http://localhost:1313" \
|
||||
|| prefix="https://mhoush.com"
|
||||
|
||||
echo "$prefix/$choice/"
|
||||
25
env/.local/scripts/mkhpadir
vendored
Executable file
25
env/.local/scripts/mkhpadir
vendored
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/bin/zsh
|
||||
|
||||
# Creates a new home performance assesment directory, from the skeleton
|
||||
# directory.
|
||||
|
||||
sdate="$(date '+%Y.%m.%d' | cut -c3-)"
|
||||
customerName="$1"
|
||||
dirName="${sdate}.${customerName}_HPA"
|
||||
skelPath="$SKELETONDIR/hpa"
|
||||
|
||||
#-------------------- MAIN --------------------
|
||||
|
||||
if [ -z $customerName ]; then
|
||||
echo "Customer name should not be empty." && exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d $skelPath ]; then
|
||||
echo "Could not find skeleton directory." && exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d $PROPOSALS ]; then
|
||||
echo "Could not find proposals directory." && exit 1
|
||||
fi
|
||||
|
||||
cp -R "$skelPath" "$PROPOSALS/$dirName"
|
||||
147
env/.local/scripts/mktrans
vendored
Executable file
147
env/.local/scripts/mktrans
vendored
Executable file
@@ -0,0 +1,147 @@
|
||||
#!/bin/bash
|
||||
# B9 June 2017
|
||||
|
||||
# mktrans
|
||||
# This is similar to ImageMagick's bg_removal script, but much higher
|
||||
# quality. (It's also faster and simpler to use.)
|
||||
#
|
||||
# For a sample, run these commands:
|
||||
# convert logo: logo.png
|
||||
# mktrans logo.png
|
||||
# display logo-transparent.png
|
||||
|
||||
|
||||
# Fuzz is how far off the background color can be (in percent).
|
||||
# This is important for getting good antialiasing.
|
||||
defaultfuzz=20
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
|
||||
mktrans: Convert images into shaped transparent pngs by floodfilling
|
||||
the background with transparency (antialiased alpha channel).
|
||||
Unless a different starting pixel is specified, the top left
|
||||
pixel is used as the "background" color to remove and
|
||||
floodfill starts from all four image edges,
|
||||
|
||||
Typical usage:
|
||||
|
||||
mktrans foo.jpg (creates foo-transparent.png)
|
||||
|
||||
Usage: mktrans [-f <fuzz>] [-s|-S] [-p <x>,<y>] [-v] <files ... >
|
||||
|
||||
-f <fuzz>: How loosely to match the background color (default $defaultfuzz%)
|
||||
|
||||
Advanced options:
|
||||
-s: Use speedy antialiasing (much faster, slightly less acurate)
|
||||
-S: Supress antialiasing completely. (Useful for repeated runs)
|
||||
p <x>,<y>: Floodfill from pixel at x,y instead of 0,0
|
||||
-v: Verbose
|
||||
EOF
|
||||
|
||||
# * Side note: This creates an antialiased (blurred) alpha channel
|
||||
# that is also eroded by half a pixel to avoid halos. ImageMagick's
|
||||
# morphological operations don't (yet?) work at the subpixel level,
|
||||
# so I'm blowing up the alpha channel to 200% before eroding. Since
|
||||
# this can be slow on large images, consider using the '-s' option
|
||||
# which uses a faster, lower quality antialiasing.
|
||||
|
||||
# * Running this script on an image that already has transparency will
|
||||
# erode the image due to the antialiasing. Using -S is a workaround,
|
||||
# but is not very satisfactory. Perhaps this script should remove any
|
||||
# existing transparency before manipulating the image and then add it
|
||||
# back in at the end. But then again, how often are people going to
|
||||
# want to do that? The only use I can think of is when using -p.
|
||||
|
||||
# * Because of the previous bug, if you do use -p to fill lots of
|
||||
# lagoons, you'll probably want to use -A at the same time.
|
||||
|
||||
# * Finding the coordinates for -p is a pain. It'd be nice if there was
|
||||
# a -P option which let the user click on a point (or multiple points)
|
||||
# in the image to start the floodfill.
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
fuzz=$defaultfuzz
|
||||
pixelcomma="0,0"
|
||||
pixelplus="+0+0"
|
||||
|
||||
while getopts f:sAShp:v name; do
|
||||
case $name in
|
||||
f) fuzz=$OPTARG
|
||||
;;
|
||||
s) sflag=True
|
||||
;;
|
||||
S|A) noantialias=True
|
||||
;;
|
||||
v) vflag=True
|
||||
;;
|
||||
h) usage
|
||||
;;
|
||||
p) pixelcomma=$OPTARG
|
||||
pixelplus=+${OPTARG%,*}+${OPTARG#*,}
|
||||
pflag=True
|
||||
;;
|
||||
*) usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1))
|
||||
[[ "$#" != 0 ]] || usage
|
||||
|
||||
|
||||
for filename; do
|
||||
# Get color of 0,0 (top left) pixel
|
||||
color=$(convert "$filename" -format "%[pixel:p{$pixelcomma}]" info:-)
|
||||
if [[ "$color" == *rgba*",0)" ]]; then
|
||||
color="${color%,0)},1)" # Floodfill only works with opaque colors.
|
||||
fi
|
||||
if [[ "$color" == "none" ]]; then
|
||||
echo "Error: $filename: pixel at $pixelcomma is completely transparent. Cannot floodfill." >&2
|
||||
continue
|
||||
fi
|
||||
|
||||
options=""
|
||||
if [ -z "$pflag" ]; then
|
||||
# Add a 1 pixel border so we'll fill from the bottom and sides as well.
|
||||
options+=" -bordercolor $color -border 1 "
|
||||
fi
|
||||
# In a new stack, make a copy of the image
|
||||
options+=" ( +clone "
|
||||
# [copy] floodfill with transparency ("none") starting at top-left
|
||||
options+=" -fuzz $fuzz% -fill none -floodfill $pixelplus $color"
|
||||
# [copy] extract just the transparency (alpha channel)
|
||||
options+=" -alpha extract"
|
||||
|
||||
if [ -z "$noantialias" ]; then
|
||||
if [ -z "$sflag" ]; then
|
||||
# [copy] blow up the alpha channel so we can do sub-pixel morphology
|
||||
options+=" -geometry 200%"
|
||||
# [copy] blur the alpha channel to make it antialiased
|
||||
options+=" -blur 0x0.5"
|
||||
# [copy] shrink the region that is opaque by half a pixel.
|
||||
options+=" -morphology erode square:1"
|
||||
# [copy] scale the alpha channel back to normal size.
|
||||
options+=" -geometry 50%"
|
||||
else # sflag: speedy antialias
|
||||
# [copy] blur the alpha channel to make it antialiased
|
||||
options+=" -blur 0x1"
|
||||
# [copy] only antialias inside the figure (<50% opacity becomes 0%)
|
||||
options+=" -level 50%,100%"
|
||||
fi
|
||||
fi
|
||||
# [copy] end the stack.
|
||||
options+=" ) "
|
||||
# Compose the original image and the copy's alpha channel.
|
||||
options+=" -compose CopyOpacity -composite"
|
||||
if [ -z "$pflag" ]; then
|
||||
# Remove the 1 pixel border we added
|
||||
options+=" -shave 1"
|
||||
fi
|
||||
|
||||
[ "$vflag" ] && echo convert "$filename" $options "${filename%.*}-transparent.png"
|
||||
|
||||
convert "$filename" $options "${filename%.*}-transparent.png"
|
||||
done
|
||||
15
env/.local/scripts/mv-all-workspaces-to-monitor
vendored
Executable file
15
env/.local/scripts/mv-all-workspaces-to-monitor
vendored
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Moves all workspaces to the passed in monitor id, which can be useful when
|
||||
# connecting or disconnecting from a monitor.
|
||||
|
||||
MONITOR=$1
|
||||
|
||||
if [ ! $# = 1 ]; then
|
||||
echo "Usage: mv-all-workspaces-to-monitor <monitor-id>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
hyprctl workspaces -j |
|
||||
jq '.[] | select(.monitorID != "$MONITOR") | .id' |
|
||||
xargs -I{} hyprctl dispatch moveworkspacetomonitor {} "$MONITOR" >/dev/null 2>&1
|
||||
11
env/.local/scripts/ncis
vendored
Executable file
11
env/.local/scripts/ncis
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Creates a new `zet` inside the NCI Summit `Zettlekasten`
|
||||
|
||||
_main() {
|
||||
ZETDIR="$HOME/Documents/NCISummit" eval zet "$@"
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
98
env/.local/scripts/newx
vendored
Executable file
98
env/.local/scripts/newx
vendored
Executable file
@@ -0,0 +1,98 @@
|
||||
#!/bin/zsh
|
||||
|
||||
# Creates a new executable file.
|
||||
|
||||
declare -a localOpt
|
||||
declare -a functionOpt
|
||||
declare -a shellOpt=("zsh")
|
||||
declare -a helpOpt
|
||||
DEBUG="$(env | grep DEBUG)"
|
||||
|
||||
zparseopts -D -K -- \
|
||||
{l,-local}+:=localOpt \
|
||||
{f,-function}+:=functionOpt \
|
||||
{s,-shell}+=shellOpt \
|
||||
{h,-help}=helpOpt
|
||||
|
||||
shell=${shellOpt[-1]}
|
||||
localPath=${localOpt[-1]}
|
||||
|
||||
#-------------------- Helpers --------------------
|
||||
function usage() {
|
||||
cat << EOF
|
||||
newx: Create new executable (script, function, or local script).
|
||||
|
||||
Typical usage:
|
||||
|
||||
newx foo (creates new script named 'foo')
|
||||
|
||||
Usage: newx [-l <name>] [-f <name>] [-s <shell>]
|
||||
|
||||
-l | --local <name>: Create a script in current directory.
|
||||
-f | --function <name>: Create a function.
|
||||
|
||||
Advanced options:
|
||||
-s | --shell <shell>: Customize the shell for the script.
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
function debug_print() {
|
||||
[ -n "$DEBUG" ] \
|
||||
&& echo "DEBUG: $1"
|
||||
}
|
||||
|
||||
function create_script() {
|
||||
|
||||
local script_path="$1"
|
||||
|
||||
debug_print "shell: $shell"
|
||||
debug_print "script-path: $script_path"
|
||||
|
||||
printf "#!/bin/%s\n\n" "${shell}" > "${script_path}"
|
||||
chmod +x "${script_path}"
|
||||
exec "${EDITOR}" +2 "${script_path}"
|
||||
}
|
||||
|
||||
function parse_local_path() {
|
||||
if [ -z "$localPath" ]; then
|
||||
local prefix="${1[1]}${1[2]}"
|
||||
debug_print "prefix: $prefix"
|
||||
[ "$prefix" = "./" ] && localPath="$1"
|
||||
fi
|
||||
}
|
||||
|
||||
#-------------------- Main --------------------
|
||||
|
||||
debug_print "first-arg: $1"
|
||||
|
||||
if [ -n "${helpOpt}" ]; then
|
||||
usage && exit 0
|
||||
fi
|
||||
|
||||
if [ -n "${functionOpt[-1]}" ]; then
|
||||
debug_print "function-opt: $functionOpt"
|
||||
|
||||
[ ! -d "$ZFUNCDIR" ] \
|
||||
&& echo "Function directory not found" \
|
||||
&& return 1
|
||||
|
||||
create_script "$ZFUNCDIR/${functionOpt[-1]}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
parse_local_path "$1"
|
||||
|
||||
if [ -n "$localPath" ]; then
|
||||
debug_print "local: $localPath"
|
||||
create_script "$localPath"
|
||||
return 0
|
||||
fi
|
||||
|
||||
debug_print "scripts: $1"
|
||||
[ ! -d "$SCRIPTS" ] \
|
||||
&& echo "Scripts directory not found. Set the SCRIPTS environment variable." \
|
||||
&& return 1
|
||||
|
||||
create_script "${SCRIPTS}/$1"
|
||||
|
||||
22
env/.local/scripts/nvims
vendored
Executable file
22
env/.local/scripts/nvims
vendored
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/zsh
|
||||
|
||||
# Change / select an nvim configuration.
|
||||
#
|
||||
# The configuration's need to be in the ~/.config folder
|
||||
# to work properly.
|
||||
#
|
||||
main() {
|
||||
items=("default" "m-housh" "kickstart" "lazy")
|
||||
config=$(printf "%s\n" "${items[@]}" \
|
||||
| fzf --prompt=" Neovim Config ➣ " --height=50% --layout=reverse --border --exit-0
|
||||
)
|
||||
if [ -z "$config" ]; then
|
||||
echo "Nothing selected"
|
||||
return 0
|
||||
elif [ $config == "default" ]; then
|
||||
config=""
|
||||
fi
|
||||
unset VIMINIT && unset MYVIMRC && export NVIM_APPNAME=$config && nvim $@
|
||||
}
|
||||
|
||||
main "$@"
|
||||
2
env/.local/scripts/path
vendored
Executable file
2
env/.local/scripts/path
vendored
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/zsh
|
||||
echo -e ${PATH//:/\\n}
|
||||
11
env/.local/scripts/pzet
vendored
Executable file
11
env/.local/scripts/pzet
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Creates a new `zet` inside the private `Zettlekasten`
|
||||
|
||||
_main() {
|
||||
(ZETDIR="$GHREPOS/private-zets" eval zet "$@")
|
||||
}
|
||||
|
||||
_main "$@"
|
||||
57
env/.local/scripts/termcolors
vendored
Executable file
57
env/.local/scripts/termcolors
vendored
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Prints the terminal theme regular colors (and some other escapes). For
|
||||
# "bright/bold" variation add 1; in front of the number. Useful for
|
||||
# sampling and remembering the escapes when hardcoding them into scripts
|
||||
# for portability. Keep in mind that the color names are those given for
|
||||
# the original color terminal and obviously can vary widely. For color
|
||||
# intensive output consider shortening the names to their first letter
|
||||
# instead and don't forget to wrap them within ${}. Omits (and overrides
|
||||
# any inherited) colors when not interactive/piped.
|
||||
|
||||
black=""
|
||||
red=""
|
||||
green=""
|
||||
yellow=""
|
||||
blue=""
|
||||
magenta=""
|
||||
cyan=""
|
||||
white=""
|
||||
blink=""
|
||||
reset=""
|
||||
|
||||
if test -t 1; then
|
||||
black="\e[30m"
|
||||
red="\e[31m"
|
||||
green="\e[32m"
|
||||
yellow="\e[33m"
|
||||
blue="\e[34m"
|
||||
magenta="\e[35m"
|
||||
cyan="\e[36m"
|
||||
white="\e[37m"
|
||||
blink="\e[5m"
|
||||
reset="\e[0m"
|
||||
fi
|
||||
echo POSIX
|
||||
printf "${black}black=\"\\\e[30m\"
|
||||
${red}red=\"\\\e[31m\"
|
||||
${green}green=\"\\\e[32m\"
|
||||
${yellow}yellow=\"\\\e[33m\"
|
||||
${blue}blue=\"\\\e[34m\"
|
||||
${magenta}magenta=\"\\\e[35m\"
|
||||
${cyan}cyan=\"\\\e[36m\"
|
||||
${white}white=\"\\\e[37m\"
|
||||
reset=\"\\\e[0m\"
|
||||
"
|
||||
echo
|
||||
echo BASH:
|
||||
printf "${black}black=$'\\\e[30m'
|
||||
${red}red=$'\\\e[31m'
|
||||
${green}green=$'\\\e[32m'
|
||||
${yellow}yellow=$'\\\e[33m'
|
||||
${blue}blue=$'\\\e[34m'
|
||||
${magenta}magenta=$'\\\e[35m'
|
||||
${cyan}cyan=$'\\\e[36m'
|
||||
${white}white=$'\\\e[37m'
|
||||
reset=$'\\\e[0m'
|
||||
"
|
||||
112
env/.local/scripts/tmux-sessionator
vendored
Executable file
112
env/.local/scripts/tmux-sessionator
vendored
Executable file
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
# Adapted from: https://github.com/ThePrimeagen/.dotfiles/blob/master/bin/.local/scripts/tmux-sessionizer
|
||||
|
||||
debug="${DEBUG}"
|
||||
|
||||
#################### Options ####################
|
||||
|
||||
declare -a paths=()
|
||||
declare chooseOpt=
|
||||
declare -a directory=()
|
||||
|
||||
zparseopts -D -- \
|
||||
{c,-choose}=chooseOpt \
|
||||
{d,-directory}:=directory
|
||||
|
||||
#################### Helpers ####################
|
||||
|
||||
function debug_print {
|
||||
if [ -n "$debug" ]; then
|
||||
echo "DEBUG: $1"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function path_prepend() {
|
||||
declare arg
|
||||
for arg in "$@"; do
|
||||
debug_print "arg: $arg"
|
||||
[ -d $arg ] && debug_print "arg is a directory" && paths=($arg $paths) \
|
||||
|| debug_print "arg is not a directory"
|
||||
done
|
||||
}
|
||||
|
||||
function setup_fuzzy_find_paths() {
|
||||
local path="$TMUX_SESSIONATOR_PATH"
|
||||
debug_print "path: $path"
|
||||
for arg in ${(s[:])path}; do
|
||||
path_prepend "$arg"
|
||||
done
|
||||
debug_print "paths: $paths"
|
||||
}
|
||||
|
||||
function create_session() {
|
||||
local selected_name=$1
|
||||
local selected=$2
|
||||
|
||||
tmux new-session -ds "$selected_name" -c "$selected" -n "editor"
|
||||
tmux send-keys -t editor 'n' Enter
|
||||
tmux new-window -d -n "terminal" -c "$selected"
|
||||
tmux new-window -d -n 'files' -c "$selected"
|
||||
tmux send-keys -t files 'yazi' Enter
|
||||
}
|
||||
|
||||
#################### MAIN ####################
|
||||
|
||||
declare choose="${chooseOpt[-1]}"
|
||||
declare selected=
|
||||
|
||||
if [[ -n $choose ]]; then
|
||||
debug_print "Choose from existing."
|
||||
selected=$(
|
||||
tmux list-sessions -F \#S | gum filter \
|
||||
--placeholder "Pick a session..."
|
||||
)
|
||||
elif [ ${#directory} -gt 0 ]; then
|
||||
debug_print "Using directory option."
|
||||
selected=${directory[-1]}
|
||||
if [ "$selected" = "." ] || [ "$selected" = "" ]; then
|
||||
selected="${PWD}"
|
||||
fi
|
||||
debug_print "Directory: $selected"
|
||||
|
||||
elif [[ "$#" -eq 1 ]]; then
|
||||
debug_print "Using existing session: $1"
|
||||
selected=$1
|
||||
else
|
||||
setup_fuzzy_find_paths
|
||||
debug_print "fuzzy find paths: ${paths}"
|
||||
|
||||
if [ -n "$DEBUG" ]; then
|
||||
debug_print "Exiting because in debug mode."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
selected=$(find ${paths} -mindepth 1 -maxdepth 1 -type d | fzf)
|
||||
fi
|
||||
|
||||
if [[ -z $selected ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
selected_name=$(basename "$selected" | tr . _)
|
||||
tmux_running=$(pgrep tmux)
|
||||
|
||||
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
|
||||
create_session "$selected_name" "$selected"
|
||||
# tmux new-session -s "$selected_name" -c "$selected"
|
||||
# exit 0
|
||||
elif ! tmux has-session -t "$selected_name" 2> /dev/null; then
|
||||
create_session "$selected_name" "$selected"
|
||||
fi
|
||||
|
||||
# Create a session if it doesn't exist.
|
||||
# if ! tmux has-session -t "$selected_name" 2> /dev/null; then
|
||||
# tmux new-session -ds "$selected_name" -c "$selected" -n "editor"
|
||||
# tmux send-keys -t editor 'n' Enter
|
||||
# tmux new-window -d -n "terminal" -c "$selected"
|
||||
# fi
|
||||
|
||||
[ -z $TMUX ] && tmux attach -t "$selected_name" \
|
||||
|| tmux switch-client -t "$selected_name"
|
||||
29
env/.local/scripts/toggle-desktop
vendored
Executable file
29
env/.local/scripts/toggle-desktop
vendored
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Workspace to hide everything in
|
||||
HIDE_WS="special:hidden"
|
||||
|
||||
# File to store original workspace ID
|
||||
STATE_FILE="/tmp/hypr_hide_state"
|
||||
|
||||
# Get current workspace ID
|
||||
CUR_WS=$(hyprctl -j activeworkspace | jq -r '.id')
|
||||
|
||||
# Check if we're currently hidden
|
||||
if [[ -f "$STATE_FILE" ]]; then
|
||||
# Restore windows
|
||||
ORIG_WS=$(cat "$STATE_FILE")
|
||||
for win in $(hyprctl -j clients | jq -r ".[] | select(.workspace.name | contains(\"$HIDE_WS\")) | .address"); do
|
||||
hyprctl dispatch movetoworkspace "$ORIG_WS,address:$win"
|
||||
hyprctl dispatch workspace "$ORIG_WS"
|
||||
done
|
||||
rm "$STATE_FILE"
|
||||
else
|
||||
# Hide all windows (move to special hidden workspace)
|
||||
for win in $(hyprctl -j clients | jq -r ".[] | select(.workspace.id == $CUR_WS) | .address"); do
|
||||
hyprctl dispatch movetoworkspace "$HIDE_WS,address:$win"
|
||||
hyprctl dispatch togglespecialworkspace "$HIDE_WS"
|
||||
done
|
||||
rm "$STATE_FILE"
|
||||
echo "$CUR_WS" >"$STATE_FILE"
|
||||
fi
|
||||
12
env/.local/scripts/toggle-internal-monitor
vendored
Executable file
12
env/.local/scripts/toggle-internal-monitor
vendored
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/zsh
|
||||
#
|
||||
# Toggles the state of the internal laptop monitor, which is useful
|
||||
# when I'm connected to an external monitor / docks.
|
||||
|
||||
monitor="eDP-1"
|
||||
|
||||
if hyprctl monitors | grep -q "$monitor"; then
|
||||
hyprctl keyword monitor "$monitor,disable" 1>/dev/null
|
||||
else
|
||||
hyprctl keyword monitor "$monitor,enable" 1>/dev/null
|
||||
fi
|
||||
11
env/.local/scripts/toggle-waybar
vendored
Executable file
11
env/.local/scripts/toggle-waybar
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
WAYBAR_PID=$(pgrep -x waybar)
|
||||
|
||||
if [ -n "$WAYBAR_PID" ]; then
|
||||
# kill waybar process if it's running.
|
||||
kill "$WAYBAR_PID"
|
||||
else
|
||||
# start waybar in the background.
|
||||
waybar &
|
||||
fi
|
||||
34
env/.local/scripts/urlencode
vendored
Executable file
34
env/.local/scripts/urlencode
vendored
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
#!/bin/bash
|
||||
|
||||
# yeah, i totally stole this from stack exchange, no shame
|
||||
|
||||
rawurlencode() {
|
||||
local string="${1}"
|
||||
local strlen=${#string}
|
||||
local encoded=""
|
||||
local pos c o
|
||||
|
||||
for ((pos = 0; pos < strlen; pos++)); do
|
||||
c=${string:$pos:1}
|
||||
case "$c" in
|
||||
[-_.~a-zA-Z0-9]) o="${c}" ;;
|
||||
*) printf -v o '%%%02x' "'$c'" ;;
|
||||
esac
|
||||
encoded+="${o}"
|
||||
done
|
||||
echo "${encoded}" # You can either set a return variable (FASTER)
|
||||
REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p
|
||||
}
|
||||
|
||||
if test -n "$1"; then
|
||||
rawurlencode "$*"
|
||||
exit
|
||||
fi
|
||||
|
||||
IFS=
|
||||
while read -r line; do
|
||||
rawurlencode "$line"
|
||||
done
|
||||
79
env/.local/scripts/vault-gopass-client
vendored
Executable file
79
env/.local/scripts/vault-gopass-client
vendored
Executable file
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env zsh
|
||||
#
|
||||
# An adapter script to use gopass to store and retrieve passwords for ansible vault.
|
||||
#
|
||||
# When calling from ansible vault it get's passed --vault-id [ID] which is the id
|
||||
# of the secret to retrieve.
|
||||
#
|
||||
|
||||
local secretPath="ansible"
|
||||
|
||||
function usage() {
|
||||
cat <<EOF
|
||||
|
||||
An adapter script that integrates gopass as storage for ansible vault id's.
|
||||
|
||||
To retreive a secret based on the vault id, then pass the '--vault-id' flag with an
|
||||
associated [ID] to look for. (This is generally handled / passed in by the ansible-vault
|
||||
command)
|
||||
|
||||
You can also call this script with the '--set' flag and an [ID] argument
|
||||
to create a new secret for the given id. The default behavior of the
|
||||
set option is to prompt for the secret, you can optionally pass the '--generate'
|
||||
flag to automatically generate a secret. If an [ID] argument is not supplied to
|
||||
the set option then we will prompt for the id to store the secret under.
|
||||
|
||||
Secrets are stored in the default password store at '$secretPath/<ID>'.
|
||||
|
||||
Usage: vault-gopass-client [-s | --set] [-g | --generate] [--vault-id <ID>] [ID]
|
||||
|
||||
-s | --set: Set a new secret for the given ID.
|
||||
-g | --generate: Used with the set option to automatically generate the secret.
|
||||
--vault-id <ID>: Used to retrieve a secret for the given ID.
|
||||
-h | --help: Show this usage message.
|
||||
|
||||
Examples:
|
||||
|
||||
# Automatically generate a secret for the 'foo' id.
|
||||
$ vault-gopass --set --generate foo
|
||||
|
||||
# Retrieve the secret for 'foo' and print it to stdout.
|
||||
$ vault-gopass --vault-id foo
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
# parse the passed in options, failing if unrecognized options are given.
|
||||
zparseopts -D -E -F - \
|
||||
g=generateFlag -generate=generateFlag \
|
||||
h=helpFlag -help=helpFlag \
|
||||
s=setFlag -set=setFlag \
|
||||
-vault-id:=vaultId \
|
||||
|| exit 1
|
||||
|
||||
# check for the help flag, show usage and exit.
|
||||
[ ${#helpFlag} = 1 ] && usage && exit 0
|
||||
|
||||
if [ ${#vaultId} = 2 ]; then
|
||||
# we received the vault-id option, so we print the
|
||||
# secret to stdout
|
||||
password=$(gopass show --password "$secretPath/${vaultId[-1]}")
|
||||
echo "$password"
|
||||
exit 0
|
||||
elif [ ${#setFlag} = 1 ]; then
|
||||
|
||||
# Use the first argument as the id, we ask for an id
|
||||
# if not supplied.
|
||||
local id=$1
|
||||
if [ "$id" = "" ]; then
|
||||
read -r id\?"Vault ID: "
|
||||
fi
|
||||
|
||||
# Check for generate flag to automatically generate a password.
|
||||
[ ${#generateFlag} = 1 ] \
|
||||
&& gopass generate "$secretPath/$id" 24 \
|
||||
&& exit 0
|
||||
|
||||
# Insert a password prompting the user to supply it.
|
||||
gopass insert "$secretPath/$id"
|
||||
fi
|
||||
4
env/.local/scripts/waybar-restart
vendored
Executable file
4
env/.local/scripts/waybar-restart
vendored
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/zsh
|
||||
|
||||
pkill -x waybar
|
||||
setsid uwsm app -- waybar >/dev/null 2>&1 &
|
||||
27
env/.local/scripts/window-toggle-floating
vendored
Executable file
27
env/.local/scripts/window-toggle-floating
vendored
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Float's a window, setting it's height and width and centering.
|
||||
|
||||
# The percentage of the screen size for the floating window.
|
||||
WIDTH_PERCENT=80
|
||||
HEIGHT_PERCENT=40
|
||||
|
||||
floating=$(hyprctl activewindow -j | jq '.floating')
|
||||
|
||||
if [ "$floating" = "true" ]; then
|
||||
hyprctl dispatch togglefloating
|
||||
else
|
||||
monitor=$(hyprctl monitors -j | jq '.[] | select(.focused == true)')
|
||||
mw=$(echo "$monitor" | jq '.width')
|
||||
mh=$(echo "$monitor" | jq '.height')
|
||||
ms=$(echo "$monitor" | jq '.scale')
|
||||
|
||||
echo "scale: $ms"
|
||||
|
||||
neww=$(echo "scale=6; (($mw / $ms) * $WIDTH_PERCENT / 100)" | bc)
|
||||
newh=$(echo "scale=6; (($mh / $ms) * $HEIGHT_PERCENT / 100)" | bc)
|
||||
|
||||
hyprctl dispatch togglefloating &&
|
||||
hyprctl dispatch resizeactive exact $neww $newh &&
|
||||
hyprctl dispatch centerwindow
|
||||
fi
|
||||
2
env/.zshenv
vendored
2
env/.zshenv
vendored
@@ -47,7 +47,7 @@ export NAP_CONFIG="$HOME/.config/nap/config.yaml"
|
||||
export PDFS="$HOME/Library/Mobile Documents/com~apple~Preview/Documents"
|
||||
export PROPOSALS="$HOME/Library/Mobile Documents/com~apple~CloudDocs/Work/Proposals"
|
||||
export SCREENSHOTS="$BUCKET/Pictures/Screenshots"
|
||||
export SCRIPTS="$XDG_DATA_HOME/scripts"
|
||||
export SCRIPTS="$$HOME/.local/scripts"
|
||||
export SITES="$GHREPOS/sites"
|
||||
export SKELETONDIR="$DOTFILES/skeleton"
|
||||
export WORK="$HOME/Library/Mobile Documents/com~apple~CloudDocs/Work"
|
||||
|
||||
Reference in New Issue
Block a user