5 releases

0.1.5 Sep 6, 2023
0.1.4 Apr 10, 2023

#1420 in Command line utilities

28 downloads per month

MIT license

31KB
640 lines

Bmark

Have you ever opened a terminal, just to spend the next few seconds navigating to the right folder? No more! Introducing bmark, the local bookmark manager. Search through your local bookmarks with a dmenu-like fuzzy finder, and open a terminal right in that directory!

Features

  • Quickly add and manage local bookmarks from the terminal
  • Open a terminal emulator directly in a bookmarked location, picked with a dmenu-like fuzzy-finder.
  • Navigate to bookmarked locations with shell aliases (see aliases).

Dependencies

This tool has been tested on fedora linux and nixos, and should work on all linux distros. MacOs and Windows are currently not supported, but may be implemented in the future.

For this tool to work out of the box, you will need the following installed on your system:

Even though these programs are the default, they are not strictly required as they can be swapped out for similar ones using the configuration file.

Quick Start

From zero to bmark.

Install cargo and the default programs.

Fedora

sudo dnf install cargo rofi kitty neovim

Now install bmark.

cargo install bmark

If you have not already, add the ~/.cargo/bin folder to your $PATH. This can be done by adding this line to your ~/.bashrc or ~/.zshrc:

PATH=$HOME/.cargo/bin:$PATH

You should now be able to run bmark in your terminal!

To enable bmark's navigation aliases, you also need to source the aliases.sh file. The command for doing this can be automatically added to your shell config like this:

# For bash:
bmark config source-cmd >> ~/.bashrc && bash

# For zsh: 
bmark config source-cmd >> ~/.zshrc && zsh

All done!

Commands

Get a quick overview by running with no arguments:

bmark

Output:

Optional arguments:
  -h, --help     print help message
  -v, --verbose  be verbose

Subcommands:
  add     add a bookmark to the current working directory
  edit    edit bookmarks in a text editor
  list    list all stored bookmarks
  open    open a new terminal in a bookmarked location
  rm      remove a bookmark with a given name
  config  commands for managing bmark configuration
  update  update shell aliases file

add

Add a bookmark to the current working directory. By default this bookmark will be named the same as to the current directory (ex: "foo/bar" -> "bar"), but you can specify a different name by providing it.

edit

Edit the bookmarks.toml file directly in your editor. The editor is determined by the editor_cmd option (default is 'nvim').

list

List the current bookmarks in the terminal.

open

Launch dmenu-like program, search through bookmarks and open a terminal in the selected location. The terminal and dmenu-like program is determined by the user configuration (default is 'kitty' and 'rofi').

rm

Remove a bookmark by its name.

Config

Commands for managing configuration.

See configuration.

update

Update the aliases file (see aliases). This is done automatically whenever you alter your bookmarks file through. This command is only usefull if you manually open and the bookmarks.toml file without using bmark edit. The command for doing this can be generated like this:

bmark config source-cmd

Aliases

bmark automatically created a file called aliases.sh in the data directory. This file defines shell aliases, that navigate to all your bookmarks.

If you you have a bookmark called "myMark" you can navigate to it like this:

_myMark

All the bookmark aliases are prefixed with '_' by default. This can be changed with the alias_prefix option.

To enable this in your shell, you need to source the alias file from your shell configuration file (ex: .bashrc for .zshrc).

Configuration

bmark configuration is done using the configuration file. This file is located in the configuration directory (ex: ~/.config/bmark/config.toml). To create a config file with the default values run the following command:

bmark config create

Edit the configuration file easily with this command:

bmark config edit

To show the current config, run this command:

bmark config show

List of Configuration Values

Option Default Value
data_dir "~/.local/share/bmark"
dmenu_cmd "rofi -matching fuzzy -dmenu"
editor_cmd "nvim"
terminal_cmd "kitty --detach"
alias_prefix "_"
show_paths false
display_sep " : "

Description of Values

data_dir

The directory where the bookmarks.toml and aliases.sh file is stored.

dmenu_cmd

The dmenu-like command is used for fuzzy-finding through bookmarks. This program should (like dmenu) take input from a pipe, and output the selected line to stdout. To check if a program is suitable for this you can run the following:

seq 20 | <dmenu_cmd>

This should give you a menu with the numbers from 1 to 20, when you pick one, it should be output in the terminal.

If your command works, you can make bmark use that by adding a like to the '~/.config/bmark/config.toml' file:

dmenu_cmd = "<dmenu_cmd>"

The default command is rofi -dmenu.

Using Actual Dmenu

If you want to use the actual dmenu instead of rofi, simply add this to your config .

dmenu_cmd = "dmenu"

(be sure to have rofi installed)

editor_cmd

The editor command is run whenever you ask bmark to edit a file (ex: bmark edit). This command should be able to be used like this:

<editor_cmd> <file>

For this a terminal based editor like neovim is recommended.

terminal_cmd

The terminal command is the command used for spawning terminal emulators at the desired locations. This command should be able to spawn a terminal in the root directory like this:

<terminal_cmd> /

If you are not using the kitty terminal, you should probably change this.

alias_prefix

The prefix in front of the bookmark name for generated aliases.

show_paths

Whether or not, to show paths in the dmenu-like fuzzy finder. If false, the display_sep has no effect.

display_sep

The characters separating the bookmark names from their paths when listing or searching through your bookmarks.

Dependencies

~3–14MB
~122K SLoC