2019-03-24 17:05:34 +01:00
|
|
|
# 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
|
2019-03-24 17:28:56 +01:00
|
|
|
#
|
|
|
|
# `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.
|
2019-03-24 17:05:34 +01:00
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
2019-03-24 17:28:56 +01:00
|
|
|
# Basic configuration
|
|
|
|
set hidden on
|
2019-10-09 13:13:56 +02:00
|
|
|
set info size:time
|
|
|
|
set sortby time
|
|
|
|
set period 1 # auto-refreshes the view
|
2019-03-24 17:28:56 +01:00
|
|
|
|
2019-03-24 17:05:34 +01:00
|
|
|
# Arguably the most import function herein
|
|
|
|
cmd help $lf -doc | less
|
|
|
|
|
|
|
|
# delete a file, dir
|
|
|
|
map D delete
|
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
# reload the view
|
|
|
|
map r load
|
|
|
|
|
|
|
|
# rename files
|
|
|
|
cmd rename %[ -e $1 ] && printf 'file exists' || mv $f $1
|
2019-03-24 17:05:34 +01:00
|
|
|
map R push :rename<space>
|
|
|
|
|
|
|
|
cmd mkdir %{{
|
2019-10-09 13:13:56 +02:00
|
|
|
# mkdir and cd into that dir
|
2019-03-24 17:05:34 +01:00
|
|
|
mkdir -p "$1"
|
|
|
|
}}
|
|
|
|
map + push :mkdir<space>
|
|
|
|
|
|
|
|
cmd touch %{{
|
|
|
|
# Create a file
|
|
|
|
touch "$1"
|
|
|
|
}}
|
2019-10-09 13:13:56 +02:00
|
|
|
map c push :touch<space> # this interferes with `clear` command
|
2019-03-24 17:05:34 +01:00
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
cmd encrypt %{{
|
|
|
|
# depends on my shell function, encrypt
|
|
|
|
zsh -i -c "encrypt $f"
|
2019-03-24 17:05:34 +01:00
|
|
|
}}
|
2019-10-09 13:13:56 +02:00
|
|
|
map xe :encrypt
|
2019-03-24 17:05:34 +01:00
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
cmd decrypt %{{
|
|
|
|
# depends on my shell function, decrypt
|
|
|
|
zsh -i -c "decrypt $f"
|
2019-03-24 17:05:34 +01:00
|
|
|
}}
|
2019-10-09 13:13:56 +02:00
|
|
|
map xE :decrypt
|
2019-03-24 17:05:34 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
}}
|
2019-03-24 17:28:56 +01:00
|
|
|
map xa :archive
|
2019-03-24 17:05:34 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
}}
|
2019-03-24 17:28:56 +01:00
|
|
|
map xA: unarchive
|
2019-03-24 17:05:34 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
}}
|
2019-03-24 17:28:56 +01:00
|
|
|
map xt :tar
|
2019-03-24 17:05:34 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
}}
|
2019-03-24 17:28:56 +01:00
|
|
|
map xT :untar
|
2019-03-24 17:05:34 +01:00
|
|
|
|
|
|
|
cmd zip %{{
|
|
|
|
# zip a directory
|
|
|
|
set -f
|
|
|
|
zip -r "$f.zip" "$(basename $f)"
|
|
|
|
rm -rf "$f"
|
|
|
|
}}
|
2019-03-24 17:28:56 +01:00
|
|
|
map xz :zip
|
2019-03-24 17:05:34 +01:00
|
|
|
|
|
|
|
cmd unzip %{{
|
|
|
|
# unzip a directory
|
|
|
|
set -f
|
|
|
|
unzip "$f"
|
|
|
|
rm "$f"
|
2019-03-24 17:28:56 +01:00
|
|
|
}}
|
|
|
|
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
|