Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add suport for adding main commands, plugins #342

Closed
wants to merge 1 commit into from

Conversation

hansmansson
Copy link

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.

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
Copy link
Collaborator

alerque commented Mar 5, 2024

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
Copy link
Author

hansmansson commented Mar 6, 2024

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
Copy link
Author

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

@hansmansson hansmansson closed this Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants