feat: Moves local scripts directory. Handles systemd configurations.

This commit is contained in:
2025-09-28 10:04:15 -04:00
parent e5baef9bac
commit 28903f8078
50 changed files with 323 additions and 271 deletions

View File

@@ -1,20 +0,0 @@
#!/bin/bash
INTERNAL="eDP-1" # check with `hyprctl monitors`
# Check lid event handler with:
#
# grep -A5 -i lid /proc/bus/input/devices
#
# The event is contained in the H: Handlers=kbd event<N>
#
DEVICE="/dev/input/event0" # replace with your lid event device
evtest --grab "$DEVICE" |
while read -r line; do
if echo "$line" | grep -q "SW_LID.*value 1"; then
hyprctl keyword monitor "$INTERNAL,disable"
elif echo "$line" | grep -q "SW_LID.*value 0"; then
hyprctl keyword monitor "$INTERNAL,preferred,auto,auto"
fi
done

View File

@@ -1,12 +0,0 @@
#!/bin/sh
set -e
font_dir="$(brew --prefix)/share/figlet/fonts"
for font in "${font_dir}"/*.flf; do
clear
echo "FONT: $font"
figlet -f "${font}" hello
read -r line
done

View File

@@ -1,129 +0,0 @@
#!/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

View File

@@ -1,8 +0,0 @@
#!/bin/sh
set -e
message="${1:-m-housh}"
font="${2:-puffy}"
echo "${message}" | figlet -c -f "${font}"

View File

@@ -1,9 +0,0 @@
#!/bin/sh
if [ "$(uname -n)" = "Michaels-Mac-mini.local" ]; then
echo "Removing derived data folders"
rm -r /Volumes/Bucket/Library/Developer/Xcode/DerivedData
else
echo "Removing derived data folders"
rm -r ~/Library/Developer/Xcode/DerivedData/*
fi

View File

@@ -1,8 +0,0 @@
#!/bin/zsh
# adapted from...
# https://github.com/rwxrob/dot/blob/main/scripts/cmt
while IFS= read -r line; do
echo "${1:-#} $line"
done

View File

@@ -1,5 +0,0 @@
#!/bin/bash
url="https://lite.duckduckgo.com/lite?kd=1&kp=1&q=$(urlencode "$*")"
exec lynx -vikeys "$url"

View File

@@ -1,16 +0,0 @@
#!/bin/bash
# Create a new figlet (ascii art) from the input.
figl() {
font=${FIGL_FONT:-puffy}
declare -a buf
while IFS= read -r line; do
buf+=("$line")
done
for line in "${buf[@]}"; do
figlet -f "$font" -c "${line}" | head -6
done
}
figl "$*"

View File

@@ -1,11 +0,0 @@
#!/bin/bash
set -e
# Creates a new `zet` inside the $HAAS/documents repository
_main() {
(ZETDIR="$HAAS/documents" eval zet "$@")
}
_main "$@"

View File

@@ -1,11 +0,0 @@
#!/bin/bash
set -e
# Creates a new `zet` inside the House Call Pro `Zettlekasten`
_main() {
(ZETDIR="$HAAS/processes" eval zet "$@")
}
_main "$@"

View File

@@ -1,12 +0,0 @@
#!/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 "$@"

View File

@@ -1,11 +0,0 @@
#!/bin/bash
set -e
# Creates a new `zet` inside the House Call Pro `Zettlekasten`
_main() {
(ZETDIR="$HCP_NOTES" eval zet "$@")
}
_main "$@"

View File

@@ -1,11 +0,0 @@
#!/bin/bash
set -e
# Creates a new `zet` inside the House Call Pro `Zettlekasten`
_main() {
(ZETDIR="$HXZET" eval zet "$@")
}
_main "$@"

View File

@@ -1,4 +0,0 @@
#!/bin/sh
date -u '+%Y%m%d%H%M%S'

View File

@@ -1,58 +0,0 @@
#!/bin/sh
# Creates symlinks from external application directory
# to another directory so applications are seen in
# spotlight searches and launchpad.
set -e
app_dir=""
destination_dir=""
# Parses the input arguments. If 2 arguments are passed in, then
# the first is where we search for applications (source) and the second
# argument is the destination directory for the symlinks to be placed in
#
# If one argument is passed in, then it is used as the destination directory
# and we use the default source directory.
_parse_args() {
arg_count="$#"
app_dir="/Volumes/M1 Mac-Mini External Drive/Applications"
destination_dir="${HOME}/Application"
if test "$arg_count" -eq 1; then
destination_dir="$1"
elif test "$arg_count" -eq 2; then
app_dir="$1"
destination_dir="$2"
fi
}
# Checks if the `app_dir` exists.
_is_mounted() {
if ! test -d "$app_dir"; then
echo "Application directory does not exist or is not mounted" >&2
return 1
fi
}
# ---------------- main -------------------
main() {
_parse_args "$@"
test -d "${destination_dir}" || echo "Destination does not exist" >&2
if test _is_mounted; then
for app in "${app_dir}"/*.app; do
destination="${destination_dir}/$(basename "${app}")"
if test -e "${destination}"; then
echo "Destination already exists: ${destination}. Skipping!" >&2
continue
fi
# remove echo to do real work.
echo ln -sv "${app}" "${destination}" >&2
done
fi
}
main "$@"

View File

@@ -1,66 +0,0 @@
#!/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/"

View File

@@ -1,25 +0,0 @@
#!/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"

View File

@@ -1,147 +0,0 @@
#!/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

View File

@@ -1,11 +0,0 @@
#!/bin/bash
set -e
# Creates a new `zet` inside the NCI Summit `Zettlekasten`
_main() {
ZETDIR="$HOME/Documents/NCISummit" eval zet "$@"
}
_main "$@"

View File

@@ -1,98 +0,0 @@
#!/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"

View File

@@ -1,22 +0,0 @@
#!/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 "$@"

View File

@@ -1,2 +0,0 @@
#!/bin/zsh
echo -e ${PATH//:/\\n}

View File

@@ -1,94 +0,0 @@
#!/usr/bin/env zsh
# Posts to facebook group and personal page.
#
# Typical usage would be to generate a link to the latest
# blog post and send to facebook:
#
# `$ mhlink --last | xargs -I {} post-to-facebook -m <optional-message> {}`
#
#
#################### Options ####################
declare -a message
zparseopts -D -F -K -- \
{a,-all}=locationOpt \
{m,-message}+:=message \
{o,-offline}=offline \
{p,-personal}=locationOpt \
{h,-help}=help
baseUrl="https://graph.facebook.com/v18.0"
link=$1
message="${message[-1]}"
token=$(cat < "$HOME/.config/facebook-bot/access-token.txt")
#################### Usage ####################
function usage() {
cat <<EOF
post-to-facebook: Create posts on facebook using. This accepts
a link as an argument and a message option. Either the message
or the link (or both) needs to be supplied.
Typical usage:
post-to-facebook --message "Some message" "https://mhouhs.com/<post>"
Usage: post-to-facebook [-a] [-m <message>] [-o] [-p] <link>
-a | --all: Send the post to the group and personal pages.
-m | --message: The optional message.
-o | --offline: Do not send the request(s), but print them.
-p | --personal: Send to personal page only.
-h | --help: Show the usage.
The -a or -p options are optional, if neither is supplied then it will
only be posted to the group.
EOF
}
#################### Helpers ####################
function post() {
local url=$1
if [ -n "$offline" ]; then
echo "Offline mode, request not being sent."
http --offline --ignore-stdin POST "$url" access_token=="$token" \
link="$link" \
message="$message"
else
http --ignore-stdin POST "$url" access_token=="$token" \
link="$link" \
message="$message"
fi
}
function post_to_group() {
group=$(cat < "$HOME/.config/facebook-bot/group.txt")
post "$baseUrl/$group/feed"
}
function post_to_personal() {
post "$baseUrl/me/feed"
}
#################### Main ####################
[ -n "$help" ] && usage && exit 0
[ -z "$link" ] && [ -z "$message" ] \
&& echo "Link or message is required." \
&& exit 1
[ "$locationOpt" = "-p" ] || [ "$locationOpt" = "--personal" ] \
&& post_to_personal \
&& exit 0
[ "$locationOpt" = "-a" ] || [ "$locationOpt" = "--all" ] \
&& post_to_personal
post_to_group

View File

@@ -1,11 +0,0 @@
#!/bin/bash
set -e
# Creates a new `zet` inside the private `Zettlekasten`
_main() {
(ZETDIR="$GHREPOS/private-zets" eval zet "$@")
}
_main "$@"

View File

@@ -1,57 +0,0 @@
#!/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'
"

View File

@@ -1,112 +0,0 @@
#!/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"

View File

@@ -1,8 +0,0 @@
#!/bin/bash
# adapted from...
# https://github.com/rwxrob/dot/blob/main/scripts/ucmt
while IFS= read -r line; do
echo "${line#* }"
done

View File

@@ -1,34 +0,0 @@
#!/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

View File

@@ -1,79 +0,0 @@
#!/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