alajmo / mani

:robot: CLI tool to help you manage repositories
https://manicli.com
MIT License
436 stars 23 forks source link

change to directory of project path #86

Open alanktwong opened 1 week ago

alanktwong commented 1 week ago

If I already have a mani.yaml configured for multiple projects, I would like to write a custom task that will change my current CLI (in my case darwin or linux) to the project path.

projects:
  example:
    path: .
    desc: A mani example

  pinto:
    path: frontend/pinto
    url: https://github.com/alajmo/pinto.git
    desc: A vim theme editor
    tags: [frontend, node]

tasks:
  go-here:
    desc: go to project path
    target:
      cwd: true  # what does this do?
    cmd: pushd "$(pwd)"

I would like mani run go-here -p pinto to change the current working directory of my shell to ./frontend/pinto

Testing this I always seem to return to working directory from where I executed mani.

One of the reasons driving this is that many multi-project development teams have repo-specific dependencies such as .npmrc, .python-version, .sdkmanrc which only kick in of the current working directory is that of the project.

alajmo commented 1 week ago

You can read the manual here or man mani.

# List of targets [optional]
targets:
  default:
    # Target all projects
    all: false

    # Target current working directory project
    cwd: false

    # Specify projects via project name
    projects: []

    # Specify projects via project path
    paths: []

    # Specify projects via project tags
    tags: []

cwd means to target the project you are standing in.

if you stand in /pinto it will target pinto, if you stand in root, it will target /example. This is mainly to avoid typing mani run <task> -p <project>.

Also note, pushd is not available in sh, which is the shell selected by default. If you want to change the default shell add shell: bash (or zsh, etc.):

shell: bash

projects:
  example:
    path: .
    desc: A mani example

  pinto:
    path: frontend/pinto
    url: https://github.com/alajmo/pinto.git
    desc: A vim theme editor
    tags: [frontend, node]

tasks:
  go-here:
    desc: go to project path
    target:
      cwd: true  # what does this do?
    cmd: pushd "$(pwd)"

If you mean you want to change your current shell's directory, that's not really possible it seems.

https://stackoverflow.com/questions/46028707/how-to-change-the-current-directory-in-go