Support KBDs for existing fns; support size fn

- Supports `size`
- Adds KBDs for encrypt/decrypt, archive/unarchive, tar/untar, etc.
- Adds explanation behind KBDs
This commit is contained in:
William Carroll 2019-03-24 16:28:56 +00:00
parent e1d42452b5
commit 72a5510dbf

View file

@ -14,6 +14,14 @@
# & shell-async shell command running asynchronously # & shell-async shell command running asynchronously
# / search search file in current directory # / search search file in current directory
# ? search-back search file in the reverse order # ? search-back search file in the reverse order
#
# `x` will be used as a generic prefix KBD for most of my user-defined KBDs. Do
# not map anything to just `x`. Instead prefer `x<char>`. Mneumonically, "x" is
# intended to resemble "eXecute".
#
# If `x<char>` does one thing; `x<uppercase-char>` should do the opposite when
# possible. This is convenient for things that pass the round-trip test like
# encrypt/decrypt, archive/unarchive.
# TODO: move most of these commands to function.zsh and call those functions # TODO: move most of these commands to function.zsh and call those functions
# herein. Especially the `archive` and `extract` functions. # herein. Especially the `archive` and `extract` functions.
@ -38,6 +46,9 @@
# TODO: support "toggle" for archive/unarchive that detects which function to # TODO: support "toggle" for archive/unarchive that detects which function to
# run based on the extension. # run based on the extension.
# Basic configuration
set hidden on
# Arguably the most import function herein # Arguably the most import function herein
cmd help $lf -doc | less cmd help $lf -doc | less
@ -73,6 +84,7 @@ cmd encrypt_file %{{
read recipient read recipient
gpg --encrypt --recipient "$recipient" "$f" && rm "$f" gpg --encrypt --recipient "$recipient" "$f" && rm "$f"
}} }}
map xe :encrypt_file
cmd decrypt_file %{{ cmd decrypt_file %{{
# Decrypts a file that was encrypted with `encrypt_file`. # Decrypts a file that was encrypted with `encrypt_file`.
@ -87,6 +99,7 @@ cmd decrypt_file %{{
gpg --decrypt "$f" >"${f%.gpg}" 2>/dev/null && rm "$f" gpg --decrypt "$f" >"${f%.gpg}" 2>/dev/null && rm "$f"
fi fi
}} }}
map xE :decrypt_file
cmd archive %{{ cmd archive %{{
# Generic function for archiving directories. # Generic function for archiving directories.
@ -101,6 +114,7 @@ cmd archive %{{
*) printf "\"$1\" is not a support archive. Aborting..." *) printf "\"$1\" is not a support archive. Aborting..."
esac esac
}} }}
map xa :archive
cmd unarchive %{{ cmd unarchive %{{
# Generic function for extracting archived directories. # Generic function for extracting archived directories.
@ -114,6 +128,7 @@ cmd unarchive %{{
*) printf "Unsupported archive type. Aborting..." *) printf "Unsupported archive type. Aborting..."
esac esac
}} }}
map xA: unarchive
cmd tar %{{ cmd tar %{{
# tars a directory # tars a directory
@ -126,6 +141,7 @@ cmd tar %{{
*) printf "\"$answer\" is not a supported answer. Aborting...";; *) printf "\"$answer\" is not a supported answer. Aborting...";;
esac esac
}} }}
map xt :tar
cmd untar %{{ cmd untar %{{
# untars a directory tar'd with `tar`. # untars a directory tar'd with `tar`.
@ -135,6 +151,7 @@ cmd untar %{{
*.tar) tar -xvf $f; rm "$f";; *.tar) tar -xvf $f; rm "$f";;
esac esac
}} }}
map xT :untar
cmd zip %{{ cmd zip %{{
# zip a directory # zip a directory
@ -142,6 +159,7 @@ cmd zip %{{
zip -r "$f.zip" "$(basename $f)" zip -r "$f.zip" "$(basename $f)"
rm -rf "$f" rm -rf "$f"
}} }}
map xz :zip
cmd unzip %{{ cmd unzip %{{
# unzip a directory # unzip a directory
@ -149,3 +167,9 @@ cmd unzip %{{
unzip "$f" unzip "$f"
rm "$f" rm "$f"
}} }}
map xZ :unzip
# outputs the size of a particular file, dir
# TODO: consider mapping this to a KBD
cmd size %du -hs "$f"
map xs :size