Cleaning up some scripts and moving to autoload functions

This commit is contained in:
2023-10-08 10:26:30 -04:00
parent 05b36efeea
commit 0f58b00f97
26 changed files with 123 additions and 102 deletions

View File

@@ -1,6 +1,6 @@
# TODO
- Remove brewfiles and use the `dots` cli manager instead.
- Add zsh functions to dots cli manager.
- Add tmux plugins to dots cli manager.
- Add tmux-powerline linking to `dots` cli manager.
- Clean up zet commands, maybe make a gum / fzf filter script.

View File

@@ -6,9 +6,9 @@
<string>com.micheal.clear-screenshots</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>zsh</string>
<string>-c</string>
<string>/Users/michael/.local/scripts/clear_screenshots</string>
<string>/Users/michael/.config/zsh/functions/clean-screenshots</string>
</array>
<key>StartCalendarInterval</key>
<dict>

View File

@@ -1,7 +0,0 @@
#!/bin/sh
session="dots"
tmux switch-client -t "$session" || \
tmux attach -t "$session" || \
tmux new-session -c "$DOTFILES" -s "$session"

View File

@@ -1,4 +0,0 @@
#!/bin/sh
# makes files executable
test -f "$1" && chmod +x "$1"

View File

@@ -1,5 +0,0 @@
#!/bin/sh
for file in "$SCREENSHOTS"/*; do
rm "$file"
done

View File

@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/zsh
# adapted from...
# https://github.com/rwxrob/dot/blob/main/scripts/cmt

View File

@@ -1,21 +0,0 @@
#!/bin/zsh
declare hide
declare show
zparseopts -D -E -K -- \
{h,-hide}=hide \
{s,-show}=show
if [ -n "$hide" ]; then
defaults write com.apple.finder CreateDesktop false && killall Finder
exit 0
fi
if [ -n "$show" ]; then
defaults write com.apple.finder CreateDesktop true && killall Finder
exit 0
fi
echo "Please pass in --hide | --show"
exit 1

View File

@@ -1,17 +0,0 @@
#!/bin/sh
# Creates an encrypted disk image from a folder
set -e
from="$1"
to="$2"
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: dmg <fromdir> <todir>"
echo ""
exit 1
fi
name="$(isosec).dmg"
hdiutil create -encryption AES-256 -srcfolder "$from" "$to/$name"

View File

@@ -1,9 +1,4 @@
#!/bin/sh
set -e
date -u '+%Y%m%d%H%M%S'
isosec() {
echo "$(date -u '+%Y%m%d%H%M%S')"
}
isosec

View File

@@ -1,5 +0,0 @@
#!/bin/bash
# Lists files and directories, including hidden files.
ls -lah --color "$@"

View File

@@ -1,12 +0,0 @@
#!/bin/sh
# Creates a directory then `cd`'s into the directory
set -e
dir="$1"
test -n "${dir}" || echo "usage: mkcd <dir>" && exit 1
mkdir "${dir}"
cd "${dir}"

View File

@@ -2,10 +2,10 @@
set -e
# Creates a new `zet` inside the House Call Pro `Zettlekasten`
# Creates a new `zet` inside the NCI Summit `Zettlekasten`
_main() {
(ZETDIR="$HOME/Documents/NCISummit" eval zet "$@")
ZETDIR="$HOME/Documents/NCISummit" eval zet "$@"
}
_main "$@"

View File

@@ -16,7 +16,7 @@ shell="${2:-sh}"
if [ -e "${path}" ]; then
echo "Already exists try:"
echo "vi ${path}"
echo "$EDITOR $path"
exit 1
fi

View File

@@ -1,13 +1,19 @@
#!/bin/sh
#!/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
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
elif [ $config == "default" ]; then
config=""
fi
unset VIMINIT && unset MYVIMRC && export NVIM_APPNAME=$config && nvim $@

View File

@@ -1,4 +0,0 @@
#!/bin/zsh
# Move into the proposals directory
cd "$HOME/Library/Mobile Documents/com~apple~CloudDocs/Work/Proposals"

View File

@@ -2,7 +2,7 @@
set -e
# Creates a new `zet` inside the House Call Pro `Zettlekasten`
# Creates a new `zet` inside the private `Zettlekasten`
_main() {
(ZETDIR="$GHREPOS/private-zets" eval zet "$@")

View File

@@ -1,5 +0,0 @@
#!/bin/sh
# opens a shell command in $EDITOR
cmd="$(command -v $1)"
test -n "$cmd" && "$EDITOR" "$cmd"

View File

@@ -2,6 +2,7 @@
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local"
export ZDOTDIR="$HOME/.config/zsh"
export ZFUNCDIR="$ZDOTDIR/functions"
export SHELL="$(which zsh)"
# Git

6
zsh/config/functions/cdots Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env zsh
function cdots() {
"$SCRIPTS/tmux-sessionator" "$DOTFILES"
}

8
zsh/config/functions/chmox Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/zsh
# makes files executable
function chmox() {
[ ! -f "$1" ] && echo "usage: chmox <file>" && return 1
chmod u+x "$1"
}

View File

@@ -0,0 +1,7 @@
#!/bin/zsh
function clean-screenshots() {
for file in "$SCREENSHOTS"/*; do
rm "$file"
done
}

23
zsh/config/functions/desktop Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/zsh
function desktop() {
declare hide
declare show
zparseopts -D -E -K -- \
{h,-hide}=hide \
{s,-show}=show
if [ -n "$hide" ]; then
defaults write com.apple.finder CreateDesktop false && killall Finder
return 0
fi
if [ -n "$show" ]; then
defaults write com.apple.finder CreateDesktop true && killall Finder
return 0
fi
echo "Please pass in --hide | --show"
return 1
}

16
zsh/config/functions/dmg Executable file
View File

@@ -0,0 +1,16 @@
#!/bin/zsh
# Creates an encrypted disk image from a folder
function dmg() {
from="$1"
to="$2"
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: dmg <fromdir> <todir>"
echo ""
return 1
fi
name="$(isosec).dmg"
hdiutil create -encryption AES-256 -srcfolder "$from" "$to/$name"
}

12
zsh/config/functions/mkcd Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env zsh
# Creates a directory then `cd`'s into the directory
function mkcd() {
dir=$1
if [ -z "$dir" ]; then
echo "usage: mkcd <dir>" && return 1
fi
mkdir "$dir"
cd "$dir"
}

View File

@@ -8,9 +8,17 @@
#
function n() {
[ -d "$1" ] || [ -z "$1" ] \
&& nvim -c ":Telescope find_files" \
&& return 0
if [ -z "$1" ]; then
local gitdir=$(git rev-parse --show-toplevel 2> /dev/null)
[ -n "$gitdir" ] \
&& nvim -c ":Telescope git_files" \
&& return 0
[ -d "$1" ] \
&& nvim -c ":Telescope find_files" \
&& return 0
fi
nvim "$1"
}

19
zsh/config/functions/vic Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/zsh
function vic() {
# opens a shell command in $EDITOR
cmd="$(command -v $1)"
[ -f "$cmd" ] \
&& "$EDITOR" "$cmd" \
&& return 0
# if command was not found try the function directory.
cmd="$ZFUNCDIR/$1"
[ -f "$cmd" ] \
&& "$EDITOR" "$cmd" \
&& return 0
echo "Command not found: $1"
return 1
}