Skip to main content

A CLI tool for managing commands like bookmarks

Project description

cmdmark

A CLI tool for managing commands like bookmarks. This Python script provides a simple way to manage and execute frequently used commands via YAML configuration files. Think of it like a bookmark manager, but for your terminal commands.

Features

  • Categorized Commands: Organize your commands into categories stored in subfolders.
  • YAML Configuration: Define commands and their descriptions in easy-to-read YAML files.
  • Interactive Selection: Choose categories, files, and commands interactively from the terminal.
  • Direct Execution: Execute selected commands directly within the script.
  • Git-Aware: Git metadata files (e.g., .git folders) are ignored when listing categories and YAML files.
  • Verbose Mode: Pass -v to show each command's description when listing commands.

Setup

  1. Installation:

    The preferred way to install cmdmark is via pipx (recommended) or pip:

    pipx install cmdmark # recommended way.
    # OR
    pip install cmdmark
    

    This will install cmdmark and its dependency, PyYAML. This project requires Python 3.12 or higher.

  2. Configuration Directory: The script uses a configuration directory located at ~/.command_bookmarks. Make sure that the directory exists. You may create some sub-directories in ~/.command_bookmarks to categorize your commands, and create yml files to store the relative commands. You can override this location by setting the environment variable CMDMARK_CONFIG_DIR.

    For example, in your shell configuration (e.g. ~/.bashrc or ~/.zshrc):

    export CMDMARK_CONFIG_DIR="$HOME/my_cmdmarks"
    
  3. YAML Files: Create YAML files within the configuration directory (or its subdirectories) to define your commands. The structure of the YAML file is as follows:

    commands:
      alias1:
        command: "your_command_here"
        description: "A short description of the command"
      alias2:
        command: "another_command"
        description: "Another description"
    
    • commands: The top-level key.
    • alias1, alias2, etc.: Short, user-friendly aliases for your commands. These are displayed in the selection menu.
    • command: The actual command to be executed.
    • description: (Optional) A brief description of the command.

Usage

  1. Run the script:

    cmdmark
    

    Use -v or --verbose to also show each command's description when listing commands.

  2. Interactive Navigation:

    • The script will first list the available categories (subfolders) within ~/.command_bookmarks.
    • Select a category by entering its number.
    • The script will then list the YAML files within the selected category.
    • Select a YAML file by entering its number.
    • Finally, the script will list the commands defined in the selected YAML file. When -v is used, each command's description is shown alongside the command itself.
    • Select a command by entering its number.
  3. Command Execution: The selected command will be executed in your terminal.

Example

Let's say you have the following structure (see tests/samples). For example, the directory might look like:

~/.command_bookmarks/
├── git/
│   ├── basic.yml
│   └── branch.yml
└── sys/
    └── disk.yml

The files under tests/sample/ provide ready-made examples you can copy into your configuration directory.

tests/sample/git/basic.yml includes common git commands:

commands:
  status:
    command: "git status"
    description: "Show the working tree status"
  add_all:
    command: "git add ."
    description: "Add all changes to staging"
  commit:
    command: "git commit -m"
    description: "Commit changes (requires message)"

tests/sample/sys/disk.yml defines a couple of useful system commands:

commands:
  check_disk:
    command: "df -h"
    description: "Check disk space usage"
  disk_usage:
    command: "du -sh ~"
    description: "Show disk usage of home directory"

Quick demo

cp -r tests/sample/* ~/.command_bookmarks/
cmdmark

Select a category (e.g. git), choose a YAML file such as basic.yml, and then pick a command like status. cmdmark will run git status right away.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cmdmark-0.0.5.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cmdmark-0.0.5-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file cmdmark-0.0.5.tar.gz.

File metadata

  • Download URL: cmdmark-0.0.5.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-26-generic

File hashes

Hashes for cmdmark-0.0.5.tar.gz
Algorithm Hash digest
SHA256 99b976fc551080909331f0dd5b3b6a612168761baff6a338f5539c9e4d040d3b
MD5 f635695e2a32d77405e819119c2e95b9
BLAKE2b-256 843181fe3d6945543d11078d4fbbec1a0e6aa8440f459c4eda828c538ab29796

See more details on using hashes here.

File details

Details for the file cmdmark-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: cmdmark-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-26-generic

File hashes

Hashes for cmdmark-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0eebfd0d89c9e43363df6830b1f969454b57cbc21a92884f64066ab89262efec
MD5 ffb19437f00d03a44db36f6825b08ef0
BLAKE2b-256 aeaf10177d74e575332b4b346dc6280e4872333348fa62c964ebc12260cba27e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page