Crates.io | lk |
lib.rs | lk |
version | 0.5.1 |
source | src |
created_at | 2021-10-04 06:25:51.355299 |
updated_at | 2024-04-15 14:44:09.832203 |
description | A command palette for your bash functions. |
homepage | |
repository | https://github.com/jamescoleuk/lk |
max_upload_size | |
id | 459981 |
size | 2,426,491 |
A command palette for your bash functions. Run in a dir with lots of bash files, fuzzy find a function, and run it. It looks like this:
You can explore your bash functions in three different ways:
The Terminal User Interface (TUI), which takes up the whole terminal window
An fzf
style inline search
By printing out lists of functions.
The default mode (--tui
or -t
).
Here's lk
run on it's own repo.
It has fuzzy find::
You hit enter to run the functioun.
The old default (--fuzzy
or -f
):
This also has fuzzy find, obviously:
You can also explore bash files via the List mode (--list
), like this:
You can drill into those files to see what functions they have. Notice that you don't need --list
now:
You can execute the functions them by passing the function name:
This means you can write scripts that use lk
, if you want to.
You can change the default mode by editing lk
's config file, which lives at ~/.config/lk/lk.toml
:
The log file lives in that directory, if you're interested or maybe want to contribute to lk
's development. You can see all of lk
's options by running lk --help
, obviously.
lk
?make
and PHONY
to do non-compile stuff to your project. lk
just lets your write proper bash without all the make
specific guff.brew tap jamescoleuk/taps
brew install lk
cargo install lk
lk
lk
executes bash functions. This sort of thing:
# A glorious function that does all the things
be_glorious() {
echo "Ta da!"
}
It executes these functions by sourcing the file, and then running the function. The equivelant of this:
. my_file.sh
be_glorious
This means anything outside a function will be executed. This is handy if you want to source other files, or set environment variables, because they'll be available to your functions. For example:
#!/usr/bin/env bash
#
# Some comments.
. "~/scripts/lib.sh"
readonly DATABASE_USER="johnsmith"
# A glorious function that does all the things
be_glorious() {
echo "Database user is ${DATABASE_USER}"
}
But this does mean most of the functional stuff in your script needs to be in functions. I appreciate this may not be how everyone wants to work, but it's fine for many use cases. The last thing I want to do is tell people how to write their scripts.
Incidentally, the comments in the scripts above will appear in --list
mode, like this:
So --list
mode allows you explore and discover your scripts, and --fuzzy
mode lets you get to functions you are perhaps already more familiar with.
If you use --fuzzy
then lk
will write the command you executed to your bash history, so you can use ctrl-r
to re-execute it. Obviously if you used --list
it will already be there.
lk
supports glob-based excludes and includes, using toml. For example:
excludes = [
"**/exclude_me",
"target",
".git",
]
You can make this global by putting it in ~/.config/lk/lk.toml
, or local by creating a lk.toml
file in, say, a project directory. If the lk.toml
file is in the same directory from which you execute lk
then it'll find and use it. You can also add includes and excludes as a switch. See lk --help
for details.
If you prepend a function with an underscore it will be ignored by lk
:
_my_ignored_function() {
echo "not happening"
}
From the crate:
cargo install lk
cargo install --force lk
.env
files.lk my_service jfdi
.If you have any typist home key dicipline and if you flap your right hand at the keyboard there's a good chance you'll type 'lk'. So it's short, and ergonomic.
lk --fuzzy
brew
.Contributions make my heart grow warm. I'm happy to support anyone who wants to contribute. Also, if you're new to Rust then I'd be happy to deepen that support to whatever extent you need.
I have previously written two similar tools:
run_lib
still has its uses. I've worked in secure environments where I could not have installed a binary. run_lib
is just a bash script.
fzf is wonderful. The --fuzzy
option in lk
comes from years of ctrl-r
fuzzy finding through my shell history with fzf
. I almost didn't implement this feature because I thought "why bother? fzf has already done it perfectly." Or rather I thought about piping from lk
to fzf
. But having the functionality implemented natively is the right thing for lk
. But you'll notice, perhaps, that the rendering of the fuzzy search in lk
draws a lot of visual inspiration from fzf
. fzf
, I love you.
Contributions are welcome. Thanks to the following for theirs: