Code Monkey home page Code Monkey logo

repocli's Introduction

REPOCLI

Command Line Interface (CLI) meant to make it easier to work with multiple repositories

It is written in go (golang), so it should be able to run on all systems, but it is only tested on Ubuntu 20.04 and 22.04

Edit a YAML config file to describe your repositories.

Commands

  • editor (alias e) - Open repo in the editor defined for that repo.
  • getdir (alias d) - Get the root directory of a repo.
  • tabtitle (alias t) - Get terminal tab title for a repo.
  • config - Command to initialize or describe a configuration-file. Can also show you the path to the config.

After you build this cli run repocli help for all commands or repocli help <command> for help on a command

Build

If you do not have go installed you can follow go's install instructions to install it. It is quite simple.

Download this repo with git: git clone [email protected]:jimoe/repocli.git

run make build to build it the default directory (~/bin) or sudo make build /opt/repocli if you, for example, want to install it in the /opt directory

Make sure the 'install' directory is in you PATH, then verify by running repocli --version

Example config

editors:
  - name: goland
    params: nosplash <path>
  - name: code
    params: .
repoes:
  - name:    some-repo-name
    path:    /home/username/code/some-repo-name
    editor:  goland
    aliases:
      - some
      - some-repo
    terminal:
      title: SOME

It can also handle mono-repoes:

  - name:    a-monorepo-name
    path:    /home/username/code/a-monorepo-name
    editor:  code
    aliases:
      - amono
    terminal:
      title: AMONO
    monorepo:
      - subpath: packages/packagename
        terminal:
          title: A packagename
      - subpath: packages/whatever
        terminal:
          title: A whatever

After the cli is built you can see a full example by running repocli config example

Practical usage

repocli editor <repo-name/alias> works out of the box, but if you want to change directory or change terminal tab title this can only be done in the shell itself. I use bash, and here are som example usage you may put in your .bashrc

Bash aliases

handleRepocliOutput() {
  local output=$1
  if [[ $output == "/"* ]]; then
    cd $output
  elif [[ ! -z $output ]]; then # not empty output
    echo "$output"
  fi
}
# open repo in configered editor:
e() {
  local alias=$1
  repocli editor $alias
}
# change directory:
c() {
  local alias=$1
  local output=$(repocli getdir $alias)
  handleRepocliOutput "$output"
}
# open editor and change directory:
ec() {
  local alias=$1
  local output=$(repocli editor --returndir $alias)
  handleRepocliOutput "$output"
}
alias ce=ec

You may then run for example e somealias or c somealias given that somealias is the name or an alias of a repo in your config-file (or even if some-alias is the name of your repo)

Set terminal tab title in bash

setRepocliTabTitleList() {
  readarray -t tabTitleList < <(/home/jim/bin/repocli tabtitle)
}
setRepocliTabTitleList
getRepocliTabTitleFromList() {
  local pwd=$(pwd -P)
  local IFS=";" # splitChar
  local line
  for line in "${tabTitleList[@]}"; do
    local parts
    read -ra parts <<< "$line" # split string into array using $IFS as split-char
    local path=${parts[0]}
    local title=${parts[1]}
    if [[ "$pwd" == "$path" ]]; then
      echo "$title"
      break
    fi
  done
}
setTabTitle() {
  local title=$(getRepocliTabTitleFromList)
  if [ -z "$title" ]; then
    title=$(pwd|rev|cut -d "/" -f 1-2|rev)
  fi
  echo -en "\e]0;$title\a"
}
PROMPT_COMMAND=setTabTitle

This should not affect your PROMPT (PS1) and it will set the tab title every time the prompt is writen

repocli's People

Contributors

jimoe avatar

Stargazers

Lars Jansøn Engvik avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.