RichiH / vcsh

config manager based on Git
GNU General Public License v2.0
2.2k stars 124 forks source link

Add suport for adding main commands, plugins #342

Closed hansmansson closed 8 months ago

hansmansson commented 8 months ago

vcsh is incredibly extendable and flexible however there is no possibility to add new commands. This is were plugins come into play. By adding plugins to $XDG_CONFIG_HOME/vcsh/plugins-enabled new commands become available. The plugin file name becomes the new command, the file must contain a function with the same name as the file, this is the entry point. A help function can also be added to get append the plugin help text to the main help text, if help is omitted a default help message is added.

alerque commented 8 months ago

Implementation wise this looks pretty good. Can you give an example of an actual use case? When do you need more access to internals while a command runs than vcsh run provides?

hansmansson commented 8 months ago

Yeah, this might be considered as feature creep. One frequent use case would be to update gitignore for all repos. I know that this could be done with a small script keept somewhere, but it would be convenient to keep such script with your vcsh config and exposed by vcsh.

By adding $HOME/.config/vcsh/plugins-enabled/update-gitignore-d with the following code this could be achieved

#!/bin/sh

help() {
  printf "   %-20s %s\n" "update-gitignore-d" "Update gitignore.d for all repos"
}

update_gitignore_d() {
  for repo in $(list); do
    GIT_DIR="$VCSH_REPO_D/$repo.git"; export GIT_DIR
    VCSH_REPO_NAME=$repo; export VCSH_REPO_NAME
    write_gitignore
    git add -f "$VCSH_BASE/.gitignore.d/$repo"
    git ci -m "Update gitignore"
  done
}

This if of course a very simple use case but you could Imagine more advance stuff.

hansmansson commented 8 months ago

I guess I can do what I want with overlays and run, just not adding to the help text.