Kowsky.kak a backup file utility for the Kakoune editor (dmere's `kak-back` sequel)

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";
};

jssec_dt_026_anc

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

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.

Gotta say, I love the name :slight_smile:

2 Likes

Was this your reasoning with the restore command. In the event you delete a working file from your current directory then just:

$ touch fileName.ext
$ kak fileName.ext

:kowsky-restore

Where back and good to go? Thats how I read you post, did I get it to plan or am ‘I out there Jerry and loving every minute of it’.

Nice job on the additional ls command and kak-back.py refactor.

Cool, yeah command line makes more sense for restoration. I had a thought when I viewed your ls command, a glob or regex on a file extension would be nice as to remove the clutter.

Talk later, bye :wave:

Exactly what you said - except you don’t even need the ‘touch’ part.

Truth is, I often use the restoration feature from the command line and not from kakoune