This project is now mature with non-blocking kakoune intergraion.
Recommendation: containerise with jlink
, see instructions below.
I run this on a computer built prior to 2013. Maximum wait time on file backup in kakoune editor < 1 second. Honestly that wait time is on a bad day, it never stops me from working continuously in kakoune editor.
I have tried to make the below easy and thorough, so any non-programmer can make kowsky.kak work.
Repository: https://bitbucket.org/KJ_Duncan/kowsky.kak/src/master/
$ git clone https://bitbucket.org/KJ_Duncan/kowsky.kak.git
Cool guys, let me know if you have any problems. Bye .
Iâve gone and done a Kowsky! A backup file utility with Kakoune editor integration.
#########
# Usage #
#########
"
kowsky cp source_file
Copies a source file from the present working directory to kowsky's backup directory
Hidden /.paths/ and /.files are ignored (no backup is created).
kowsky mv target_file
Restores a corrupt or deleted file from the kowsky backup directory to the present working directory.
The backup file remains intact. If target file was deleted from the working directory use:
$ touch target_file
To create an empty file which kowsky restores into.
kowsky [rm | --dry-run] [one | thirty | sixty | ninety | onetwenty]
Removes the catalogue of backup files > days old.
kowsky rmdir
Recursively remove backup files and kowsky created directories:
/kak-back-kowsky/backups/*.*
"
######################
# Command Line Usage #
######################
# backup a file:
$ cd /into/the/directory/where/file/is/located
$ kowsky cp source_file
# restore a file:
$ cd /into/the/directory/where/file/was/deleted/or/corrupt
$ touch fileName.ext # necessary if file was deleted
$ kowsky mv target_file # backup file remains intact
# remove a catalogue of backup files > thirty days old:
$ kowsky rm thirty
# list files for removal > thirty days old:
$ kowsky --dry-run thirty
# remove all backup files and directory /kak-back-kowsky/*:
$ kowsky rmdir
##############################
# Kakoune Editor Integration #
##############################
# repositories kowsky.kakoune file
$ mv kowsky.kakoune $XDG_CONFIG_HOME/kak/autoload/kowsky.kak
# or
$ mv kowsky.kakoune $HOME/.config/kak/autoload/kowsky.kak
permissions: drwx ---- ---- to paths /kak-back-kowsky/backups
permissions: rw- ---- ---- to files /kak-back-kowsky/backups/*.*absolute path: $HOME/.local/share/kak-back-kowsky/backups/*.*
Kowsky.kak leverages Javaâs security manager, when this application attempts to
interact with local system resources it must first have the equivalent
permission explicitly granting the access via a policy file.â[Whenever] a resource access is attempted, all code traversed by the execution
thread up to that point must have permission for that resource accessâŚâ
(Permissions in the JDK).Kowsky logs security and i/o exceptions to standard error, the output
is consistent with kakouneâs debug buffer for example::buffer *debug*
*** This is the debug buffer, where debug info will be written ***
shell stderr: <<<
Dec 05, 2020 6:05:16 PM KakBackKowsky cp
SEVERE: Unable to copy: README.md access denied (âjava.util.PropertyPermissionâ âuser.homeâ âreadâ)shell stderr: <<<
Dec 05, 2020 6:08:40 PM KakBackKowsky mkdir
SEVERE: Unable to create backup directory: access denied (âjava.io.FilePermissionâ â$HOME/.local/share/kak-back-kowsky/-â âread,write,deleteâ)
References
- Common Weakness Enumeration (CWE), 2020, âCWE CATEGORY: File Handling Issuesâ, Category ID: 1219, viewed 05 December 2020, CWE - CWE-1219: File Handling Issues (4.13)
- Kakoune 2020, â5. Configuration & Autoloadingâ, viewed 04 December 2020, GitHub - mawww/kakoune: mawww's experiment for a better code editor
- Kakoune 2020, âDebug Buffersâ, buffers.asciidoc, viewed 05 December 2020, kakoune/doc/pages/buffers.asciidoc at master ¡ mawww/kakoune ¡ GitHub
- Oracle 2020, âDefault Policy Implementation and Policy File Syntaxâ, Java Documentation, viewed 27 November 2020, Permissions in the JDK
- Oracle 2020, âFiles.isHiddenâ, java.nio.file.Files, viewed 05 December 2020, Files (Java SE 15 & JDK 15)
Inspired by dmerejkowsky original post: Create backup of each edited file, with source file kak-back.rs. Thanks Dmere.
- Merejkowsky, D 2020, âkak-spellâ, PyEnchant wrapper for Kakoune, viewed 06 December 2020, kak-spell ¡ PyPI
@author Duncan, K & Merejkowsky, D 2020, KakBackKowsky.java & kak-back.rs,
ðŸÂÂľ 418 - I'm a teapot, viewed 27 November 2020,
https://bitbucket.org/KJ_Duncan/kowsky.kak/src/master/src/main/java/KakBackKowsky.java
https://github.com/dmerejkowsky/dotfiles/blob/master/dm-tools/src/bin/kak-back.rs
@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
+----------------+----------------------+
| Object | Type |
+----------------+----------------------+
| kowsky | executable |
| jre-kowsky | custom runtime image |
| kowsky.kak | repository / module |
| kowsky.policy | java security policy |
| kowsky.kak.jar | archive for classes |
| kowsky.kakoune | kakoune intergration |
+----------------+----------------------+
âmodule-path
@see package manager sdkman for installation instructions.
$ mkdir -p build/classes build/libs
$ javac --release 15 -d build/classes \
src/main/java/au/kjd/Days.java \
src/main/java/au/kjd/KakBackKowsky.java \
src/main/java/au/kjd/kowsky.java \
src/main/java/module-info.java
$ jar --create --file build/libs/kowsky.kak.jar \
--main-class au.kjd.kowsky \
--module-version 0.2.0 \
-C build/classes/ .
$ echo 'java -Djava.security.manager -Djava.security.policy==<path-to>/kowsky.policy --module-path <path-to-kowsky-jar> --module kowsky.kak "${@:1}"' > kowsky
$ chmod u-wx,og-rwx build/libs/kowsky.kak.jar && \
chmod u-wx,og-rwx kowsky.policy && \
chmod u+rx,u-w,og-rwx kowsky
$ mv build/libs/kowsky.kak.jar $HOME/<path-to-kowsky-jar> && \
mv kowsky $HOME/local/bin/ && \
mv kowsky.policy /somewhere/you/want/
- Deitel, P 2017, âUnderstanding Java 9 Modulesâ, What they are and how to use them, Java 9 Excerpt, Oracle, viewed 05 August 2020, Understanding Java 9 Modules
-Djava.security.policy
# kowsky.policy
// '*' pwd files (non-recursive), '-' recursively walk sub-directories
// jlink: grant codeBase "jrt:/kowsky.kak"
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";
// Needed by file permissions restriction system:
permission java.lang.RuntimePermission "accessUserInformation";
};
Mapping from Code to Domains and to Permissions
kowsky.kakoune
# does the heavy lifting
hook global BufWritePost .* %{
nop %sh{ kowsky cp "${kak_hook_param}" }
}
# quick way to finish up at a foreign location
define-command kowsky-rmdir \
-docstring "recursively remove all /kak-back-kowsky/backups/*.*" %{
nop %sh{ kowsky rmdir }
}
# remove > days old = one|thirty|sixty|ninety|onetwenty
hook global KakEnd .* %{
nop %sh{ kowsky rm thirty }
}
jlink
$ jlink --output jre-kowsky \
--module-path $HOME/<path-to-jar>/kowsky:$JAVA_HOME/jmods \
--add-modules kowsky.kak,java.base,java.logging \
--compress=0 --no-man-pages
$ kak kowsky.policy
grant codeBase "jrt:/kowsky.kak" {
[...]
};
$ du -hs jre-kowsky
> 41M jre-kowsky
$ echo '<path-to>/jre-kowsky/bin/java -Djava.security.manager -Djava.security.policy==<path-to>/kowsky.policy --module kowsky.kak "${@:1}"' > kowsky
$ chmod -R og-rwx jre-kowsky && \
chmod u+rx,u-w,og-rwx kowsky && \
chmod u-wx,og-rwx kowsky.policy
$ mv jre-kowsky kowsky.policy kowsky /somewhere/you/want/
- Oracle 2020, âThe jlink Commandâ, Java SE 15, viewed 20 November 2020, The jlink Command
- OpenJDK 2017, âJEP 220: Modular Run-Time Imagesâ, viewed 05 August 2020, JEP 220: Modular Run-Time Images
gradle
$ git clone https://bitbucket.org/KJ_Duncan/kowsky.kak.git
$ cd kowsky.kak
# bitbucket does not allow *.jar files in a git clone repo
$ gradle wrapper
$ ./gradlew build # to build with tests
$ ./gradlew test --rerun-tasks
$ ls build/libs/
> kowsky.kak.jar
$ jar --update --file build/libs/kowsky.kak.jar \
--main-class au.kjd.kowsky
# in conjunction with --module-path or jlink setup
- Gradle 2020, âThe Gradle Wrapperâ, viewed 13 August 2020, Gradle Wrapper Reference
- Sdkman 2020, âGradleâ, The Software Development Kit Manager, viewed 06 December 2020, Available SDKs - SDKMAN! the Software Development Kit Manager
File Handling Issues
- CWE Category: File Handling Issues, CWE - CWE-1219: File Handling Issues (4.13)
- CWE-23: Relative Path Traversal, https://cwe.mitre.org/data/definitions/23.html
- CWE-378: Creation of Temporary File With Insecure Permissions, CWE - CWE-378: Creation of Temporary File With Insecure Permissions (4.13)
- 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 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 230+ 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.