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

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
}