diff options
author | William Carroll <wpcarro@gmail.com> | 2019-03-24T16·05+0000 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2019-03-24T16·05+0000 |
commit | 362a623a0a4ae5e8fc92fd2b44eca36e7f47cccb (patch) | |
tree | 267a61ed5de5e83488fa5af8a6fd0f348b0cae43 | |
parent | f5ace0b0a92e05fd4d1466556f2fd98ad4e6b776 (diff) |
Define functions, KBDs for lf
Defines functions for creating, deleting, renaming files. Defines functions for encrypting/decrypting files. Defines functions for archiving/unarchiving files. Adds TODOs for wishlist items. Adds `help` function to view `lf` documentation. TODO: write generic explanation of desire to share KBDs between Emacs, Vim, other programs that I can link to in documentation to avoid repeating myself.
-rw-r--r-- | configs/shared/misc/.config/lf/lfrc | 152 |
1 files changed, 151 insertions, 1 deletions
diff --git a/configs/shared/misc/.config/lf/lfrc b/configs/shared/misc/.config/lf/lfrc index 59b8e5d80676..ad04e3bdcb49 100644 --- a/configs/shared/misc/.config/lf/lfrc +++ b/configs/shared/misc/.config/lf/lfrc @@ -1 +1,151 @@ -map D delete \ No newline at end of file +# It might be possible to attempt to share KBDs between `lf` and `dired`. +# Currently shared KBDs with `dired`: +# - D: delete file +# - R: rename file +# - +: create directory +# - c: create file +# +# The following command prefixes are used by lf (taken from the docs): +# +# : read (default) builtin/custom command +# $ shell shell command +# % shell-pipe shell command running with the ui +# ! shell-wait shell command waiting for key press +# & shell-async shell command running asynchronously +# / search search file in current directory +# ? search-back search file in the reverse order + +# TODO: move most of these commands to function.zsh and call those functions +# herein. Especially the `archive` and `extract` functions. +# +# TODO: consider integrations with `xdg-open` and configuring filetypes to +# behave in expected "dwim" ways. +# +# TODO: learn more about the terms "archive", "compress", "decompress", +# "expand", "extract", etc. See if a larger abstraction can be created on top +# without sacrificing too much nuance. This might be the case of "serialize", +# "deserialize", "pickle", "unpickle", "marshal", "unmarshal", "encode", +# "decode" -- in which case, a broader abstraction would be nice to decrease the +# surface area of the vocabulary. +# +# TODO: find a way to visualize all of the bound or unbound KBDs. +# +# TODO: support polymorphic way encrypt/decrypt a file or directory. +# +# TODO: support "toggle" for encryption/decryption that detects which function +# to run based on the extension. +# +# TODO: support "toggle" for archive/unarchive that detects which function to +# run based on the extension. + +# Arguably the most import function herein +cmd help $lf -doc | less + +# delete a file, dir +map D delete + +cmd rename %{{ + # Renames files, dirs. + set -f + if [ -e "$1" ]; then + printf 'file exists' + else + mv "$f" "$1" + fi +}} +map R push :rename<space> + +cmd mkdir %{{ + mkdir -p "$1" +}} +map + push :mkdir<space> + +cmd touch %{{ + # Create a file + touch "$1" +}} +map c push :touch<space> + +cmd encrypt_file %{{ + # Encrypts the file and deletes the cleartext version. + # Run `decrypt_file` to return the file to its cleartext version. + printf "recipient: " + read recipient + gpg --encrypt --recipient "$recipient" "$f" && rm "$f" +}} + +cmd decrypt_file %{{ + # Decrypts a file that was encrypted with `encrypt_file`. + # Assumes encrypted files have the .gpg extension and decrypted files omit the + # .gpg extension. + # Deletes the original .gpg file when finished. + + # check if file exists without .gpg extension + if [ -e "${f%.gpg}" ]; then + printf "${f%.gpg} exists. Consider deleting or renaming it. Aborting..." + else + gpg --decrypt "$f" >"${f%.gpg}" 2>/dev/null && rm "$f" + fi +}} + +cmd archive %{{ + # Generic function for archiving directories. + # TODO: support selections of multiple files. + set -f + printf "Which type of archive would you like to create? (tar,tar.gz,zip) " + read answer + case $answer in + tar.gz) tar -czf "$f.tar.gz" "$(basename $f)"; rm -rf "$f";; + tar) tar -cf "$f.tar" "$(basename $f)"; rm -rf "$f";; + zip) zip -r "$f.zip" "$(basename $f)"; rm -rf "$f";; + *) printf "\"$1\" is not a support archive. Aborting..." + esac +}} + +cmd unarchive %{{ + # Generic function for extracting archived directories. + # Assumes directories were archived with the `archive`. + set -f + case $f in + *.tar.gz) tar -xzvf $f; rm "$f";; + *.tar) tar -xvf $f; rm "$f";; + *.zip) unzip "$f"; rm "$f";; + # TODO: grab extension from $f and display it in `printf` call. + *) printf "Unsupported archive type. Aborting..." + esac +}} + +cmd tar %{{ + # tars a directory + set -f + printf "gzip? (y,n) " + read answer + case $answer in + y) tar -czf "$f.tar.gz" "$(basename $f)"; rm -rf "$f";; + n) tar -cf "$f.tar" "$(basename $f)"; rm -rf "$f";; + *) printf "\"$answer\" is not a supported answer. Aborting...";; + esac +}} + +cmd untar %{{ + # untars a directory tar'd with `tar`. + set -f + case $f in + *.tar.gz) tar -xzvf $f; rm "$f";; + *.tar) tar -xvf $f; rm "$f";; + esac +}} + +cmd zip %{{ + # zip a directory + set -f + zip -r "$f.zip" "$(basename $f)" + rm -rf "$f" +}} + +cmd unzip %{{ + # unzip a directory + set -f + unzip "$f" + rm "$f" +}} \ No newline at end of file |