Giter Site home page Giter Site logo

somecho / utility-scripts Goto Github PK

View Code? Open in Web Editor NEW
13.0 1.0 1.0 57 KB

A collection of helper scripts for Clojure, Java, Ledger and Taskwarrior. Written in Clojure.

License: MIT License

Clojure 100.00%
clojure deps-edn taskwarrior babashka java ripgrep ledger-cli

utility-scripts's Introduction

Somē's utility scripts

Here are some utility scripts I wrote for myself. At first I wrote the scripts in a shell scripting language. But then I discovered Babashka and I love Clojure. I decided to port all the scripts to Clojure instead. You will need Babashka to run these scripts. These are helper tools for Clj, Java, Ledger and Taskwarrior.

Scripts included:

  1. accountsof - outputs the name of all accounts used in a Ledger journal file
  2. cljminimal - creates an ultra barebones deps.edn clj project for quick hacking
  3. depo - adds dependencies to Clojure projects. Supports deps.edn,project.clj,shadow-cljs.edn.
  4. jrun - single file Java runner
  5. keepbooks - simple transaction entry helper for Ledger CLI accounting. Supports interactive entry.
  6. on-modify-log - a Taskwarrior hook to log the latest modified task
  7. projectsof - finds directories of certain project types
  8. resumetask - resumes latest modified Taskwarrior task
  9. startnewtask - creates and starts a new Taskwarrior task
  10. stoptasks - stops all active Taskwarrior tasks
  11. taskinfo - prints the attribute of a Taskwarrior task

Installation

You need to first install Babashka.

git clone https://github.com/somecho/utility-scripts
cd utility-scripts
./install.clj 

This will copy all the scripts into ~/.local/bin. Make sure ~/.local/bin is in your path to call the scripts globally.

Uninstalling

To uninstall, simply call uninstall-some-scripts and all the scripts will be deleted from ~/.local/bin.

Outputs the names of all the accounts used in a Ledger journal file. Example: accountsof LEDGERFILE.

A script to create an ultraminimal clj project with an empty deps.edn and a singular hello world main function. To use, simply call cljminimal my-minimal-clj-project and a project called my-minimal-clj-project will be created for you. Mainly used for quick hacking and throwaway prototyping.

Adds dependencies to Clojure projects. To use, run the script at the root of a project containing a deps.edn, project.clj or shadow-cljs.edn file. If multiple config files are present, the first config file in the order of deps,project,shadow-cljs will be selected.

Usage

depo add reagent
# Added [reagent "1.2.0"]

If multiple config files are present, you can use -f to specify which file to add a dependency to.

depo add reagent -f deps.edn
# Added {reagent/reagent {:mvn/version 1.2.0}}

You can also specify a version.

depo add reagent 1.1.0
# Added [reagent "1.1.0"]

Depo can currently only search for dependencies from Clojars. For a more powerful alternative, checkout neil.

Compiles and runs a single java file. Mainly used for quick iteration of ideas. For example, you can run it in Vim with :!jrun App.java and see the output in a Vim buffer without leaving your current buffer.

Usage

jrun JAVAFILE

The JAVAFILE argument is glob-searched, so you can use App.java or App and it will still run.

A helper script to enter a simple transaction into a Ledger file.

Single entry mode

The script has the following format in single entry mode:

keepbooks -f LEDGERFILE -d DATE PAYEE? ACCOUNT_TO_DEBIT ACCOUNT_TO_CREDIT AMOUNT CURRENCY

The -d DATE field is optional. If this flag is ommitted, the current date will be used. The PAYEE field is also optional. If the PAYEE is ommitted, no payee will be entered in the transaction. The other fields ACCOUNT_TO_DEBIT, ACCOUNT_TO_CREDIT, AMOUNT and CURRENCY are required fields. The ordering is strict. Upon entering a successful command, the ledger entry will be written into the ledger file provided and also printed out in the commandline.

keepbooks -f 2023.ledger -d 2023/07/20 Sushi Bar Expenses:Restaurant Assets:Bank 30.00 EUR
# prints out:
# 2023/07/20 Sushi Bar
#   Expenses:Restaurant                       30.00 EUR
#   Assets:Bank

Interactive mode

keepbooks also supports interactive entry. Simply call keepbooks -f LEDGERFILE without any arguments and you will be prompted to enter your transaction.

A Taskwarrior hook to log latest modified task. This script is not installed in ~/.local/bin. Instead, it requires you to copy it to your Taskwarrior's hooks folder. This is usually ~/.task/hooks. Every time a task is modified, it writed the UUID of the task in a file called last-modified.data in your Taskwarrior's data.location. This hook is required for the resumetask script to work.

Searches the current working directory for project directories of a certain type. For example, calling projectsof java will return all the directories which are java projects. Requires rg to run.

Flags

  • -n - displays numbered rows
  • -i NUMBER - outputs directory with line number -i

Currently supported project types

  1. Clojure/Clj
  2. Java

Ever wanted to just restart the Taskwarrior task you stopped right before a break? With this script, you can just pick up where you left off by calling resumetask. No more trying to figure what ID your task has! This script requires the on-modify-log hook to work and the taskinfo script to work.

Why use hooks?

Some people suggest having a shell alias that starts a task and exports it as an environment variable. But since I use Syncthing to sync my tasks across devices, this will not work if I stopped a task on one device and want to resume it on another. By saving the last modified task's UUID in Taskwarrior's data.location, I can have the UUID synced as well.

Creates and immediately starts a Taskwarrior task. Use this as you would task add.

task add +admin +bookkeeping track finance # adds a task to Taskwarrior
startnewtask +admin +bookkeeping track finance # adds and starts task

Stops all active Taskwarrior tasks. Every tried task stop and gotten an error? Yeah, me too. Now you can stop all active tasks with a single stoptasks.

Prints the attribute of a Taskwarrior task. Commands follow this format:

taskinfo TASKID TASKATTRIBUTE
# example: taskinfo 40 description

The resumetask script depends on this script.

utility-scripts's People

Contributors

somecho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

utility-scripts's Issues

Create a script to start a new ledger file

At the end of the year, it's common practice to carry on this year's balance into the new financial year. The idea of this script is to have something like newledger -f lastyear.ledger -o thisyear.ledger, setting up the accounts properly.

If no input file is given, then allow key-value pairs to be given to setup the equity account. Example: newledger -o thisyear.ledger -a Assets:Cash -v '100.00 EUR' -a Liabilities:Loan -v '200.00 EUR'. Example output would be:

2024/01/01 Opening Balance
    Assets:Cash                                                100.00 EUR
    Liabilities:Loan                                           200.00 EUR
    Equity 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.