Kowsky.kak a backup file utility for the Kakoune editor.
kowsky.kak; backup=cp, restore=mv, clean=rm, clean-all=rmdir, --dry-run
sets permission rwx — --- to path /kak-back-kowsky/backups
sets permission rw- — --- to files /kak-back-kowsky/backups/*.*
ignores all .private files (names that begin with a dot) on backup.
fully qualified path: $HOME/.local/share/kak-back-kowsky/backups/*.*
/**
* I've gone and done a Kowsky!
*
* Logs to ConsoleHandler via System.err as Kakoune logs stderr in debug buffer.
*
* Requires security manager on with the command line argument:
* $ java -Djava.security.manger -Djava.security.policy==kowsky.policy
*
* Prefix all commands with entry point `kowsky`
*
* Usage:
* cp file.ext
* mv file.ext
*
* Requires a time period of `days` old:
* rm one|thirty|sixty|ninety|onetwenty
* --dry-run one|thirty|sixty|ninety|onetwenty
*
* Recursively removes all files and directory structure: /kak-back-kowsky/backups/*.*
* rmdir
*
* @param args cp, mv, rm, rmdir, --dry-run
*
* @author Duncan, K & Merejkowsky, D 2020, KakBackKowsky.java & kak-back.py,
* 🍵 418 - I'm a teapot, viewed 03 June 2020,
* https://bitbucket.org/KJ_Duncan/kowsky.kak/src/master/src/main/java/KakBackKowsky.java
* https://github.com/dmerejkowsky/dotfiles/blob/master/dm-tools/bin/kak-back
*
* @since Dizzee, R 2017, Wot U Gonna Do?, Raskit, viewed 07 June 2020,
* https://open.spotify.com/track/0XMS9iWCSKLunggRUsOd4C?si=7Uj93yQSS7q1O1dQWU3RxA
* https://youtu.be/8O0Spn2eaSk
*/
Inspired by dmerejkowsky Create backup of each edited file, with original file kak-back.py. Thanks Dmere.
See sdkman for jdk package manager.
# via build.gradle.kts
$ gradle wrapper
$ ./gradlew uberJar
# via command line
$ javac kowsky.java KakBackKowsky.java Days.java -d kowsky-classes
$ cd kowsky-classes
$ jar cvf kowsky.kak.jar *
$ rm *.class
# permissions
$ chmod u-wx,og-rwx kowsky.kak.jar
# invoke via command line
$ java -Djava.security.manager \
-Djava.security.policy==<path-to>/kowsky.policy \
-cp <path-to>/kowsky.kak.jar \
kowsky cmds...`
# invoke via an executable in /bin directory
$ echo 'java -Djava.security.manager -Djava.security.policy==<path-to>/kowsky.policy -cp <path-to>/kowsky.kak.jar kowsky "${@:1}"' > kowsky.kak
$ chmod u+x,u-w,og-rwx kowsky.kak
$ mv kowsky.kak $HOME/local/bin/
kowsky.policy
// '*' pwd files (non-recursive), '-' recursively walk subdirectories
grant codeBase "file:/<path-to>/kowsky.kak.jar" {
permission java.util.logging.LoggingPermission "control", "";
permission java.util.PropertyPermission "user.home", "read";
permission java.util.PropertyPermission "user.dir", "read";
permission java.io.FilePermission "*", "read,write";
permission java.io.FilePermission "${user.home}/.local/share/", "read,write";
permission java.io.FilePermission "${user.home}/.local/share/kak-back-kowsky", "read,write,delete";
permission java.io.FilePermission "${user.home}/.local/share/kak-back-kowsky/-", "read,write,delete";
permission java.lang.RuntimePermission "accessUserInformation";
};
Mapping from Code to Domains and to Permissions
kowsky.kak
hook global BufWritePost .* %{
nop %sh{ kowsky.kak cp "${kak_hook_param}" }
}
define-command kowsky-restore \
-docstring "restore current buffer file to its previously saved state" %{
nop %sh{ kowsky.kak mv "${kak_buffile}" }
}
define-command kowsky-rmdir \
-docstring "recursively remove all /kak-back-kowsky/backups/*.*" %{
nop %sh{ kowsky.kak rmdir }
}
# days old = one|thirty|sixty|ninety|onetwenty
hook global KakEnd .* %{
nop %sh{ kowsky.kak rm thirty }
}
File Handling Issues
- CWE Category: File Handling Issues, https://cwe.mitre.org/data/definitions/1219.html
- CWE-23: Relative Path Traversal, https://cwe.mitre.org/data/definitions/23.html
- CWE-378: Creation of Temporary File With Insecure Permissions, https://cwe.mitre.org/data/definitions/378.html
- CWE-379: Creation of Temporary File in Directory with Insecure Permissions, https://cwe.mitre.org/data/definitions/379.html
- CWE-426: Untrusted Search Path, https://cwe.mitre.org/data/definitions/426.html
- CWE-427: Uncontrolled Search Path Element, https://cwe.mitre.org/data/definitions/427.html
Kakoune General Information
Work done? Have some fun. Share any improvements, ideas or thoughts with the community on discuss.kakoune.
Kakoune is an open source modal editor. The source code lives on github mawww/kakoune.
A discussion on the repository structure of community plugins for Kakoune can be reviewed here: Standardi(s|z)ation of plugin file-structure layout #2402.
Read the Kakoune wiki for information on install options via a Plugin Manager.
Thank you to the Kakoune community 180+ contributors for a great modal editor in the terminal. I use it daily for the keyboard shortcuts.
That’s it for the readme, anything else you may need to know just pick up a book and read it Polar Bookshelf. Thanks all. Bye.