A command palette for your bash functions.
lk
searches for scripts, examines them and finds bash functions. Then it lets you run the functions through a consistant interface.
If you run lk
you might see something like this:
You can start typing and it'll search through file names and function names:
It'll also do fuzzy find:
Use the arrow keys to make a selection:
And hit enter to run the function:
You can also explore bash files via --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. If you prefer this list
mode then you can make it the default 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.
shell
brew tap jamescoleuk/taps
brew install lk
shell
cargo install lk
lk
lk
executes bash functions. This sort of thing:
```bash
be_glorious() { echo "Ta da!" } ```
It executes these functions by sourcing the file, and then running the function. The equivelant of this:
bash
. 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:
```bash
#
. "~/scripts/lib.sh" readonly DATABASE_USER="johnsmith"
beglorious() { echo "Database user is ${DATABASEUSER}" } ```
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:
toml
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
:
bash
_my_ignored_function() {
echo "not happening"
}
From the crate:
bash
cargo install lk
bash
cargo install --force lk
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..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 - my first draft and written in bash * runsh - my second draft and written in Rust
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: