A simple cli tool for switching git user easily inspired by Git-User-Switch

gitsu

A simple cli tool for switching git user easily inspired by Git-User-Switch

screenshot

Installation

Binary releases are here. issues

Homebrew

brew install matsuyoshi30/gitsu/gitsu

Go (Not recommended)

go get github.com/matsuyoshi30/gitsu

Requirements

  • Go 1.16 ~

Usage

USAGE:
   git su [global options] command [command options] [arguments...] # via Homebrew
   gitsu [global options] command [command options] [arguments...]  # via go get

COMMANDS:
   delete, d  Delete existing user
   modify, m  Modify existing user
   select, s  Select existing user
   reset, r   Remove all saved user profiles
   init, i    Initialize user config by providing an alias
   add, a     Add new user
   help, h    Shows a list of commands or help for one command

LICENSE

MIT

Comments
  • Added modify user option

    Added modify user option

    Hello, regarding #5 here is my proposition for creating user aliasing. To be honest it's a little bit ugly due to if/else statement but I think we can discuss in comments below. I think we could me some logic to external packages and make more functions to avoid repeating the same parts of code.

    Regards :)

  • Failing to select any user/config.

    Failing to select any user/config.

    Version: gitsu 0.2.1 Medium: Homebrew

    Please find attached a small screencapture of the error.

    https://user-images.githubusercontent.com/49570057/124137509-0805c200-da86-11eb-8cd9-3de4c9a8b6b3.mov

  • Fix issue #5

    Fix issue #5

    This fixes #5

    This PR fixes multiple things:

    Option to modify existing users

    Use the arrow keys to navigate: ↓ ↑ → ←
    ? Select action:
        Select git user
        Add new git user
        Delete git user
      > Modify git user
    

    Following this you can select the user to modify

    ? Select git user:
      > Dog <[email protected]>
        [foo] Foo <[email protected]>
        [rick] Rick <[email protected]>
    

    You are then guided through updating each user option (name, email, GPG key ID and alias). Leaving an option empty results in no change for this specific option.

    Support for aliases

    When adding a new user you can specify an alias. This allows you to execute gitsu <alias> which immediatly sets the git user.

    Misc

    This commit also adds a default .gitignore for Go projects (See here)

    I seperated the git config commands into their own file and combined the 3 commands into one function called SetGitConfig. This cuts down on complexity in the gitsu commands and follows DRY.

    Note

    This improves on #6 and implements the proposed behaviour from @matsuyoshi30 and @BrendanThompson

  • Rewrite: Applied DRY principle, better code structure & maintainability and new features

    Rewrite: Applied DRY principle, better code structure & maintainability and new features

    This PR introduces a complete rewrite of the tool. Most notably the following changes were made:

    CLI

    Moving CLI related code into the cmd directory. This includes the command and prompts definitions

    Logic

    Moving logic into the internal directory. All the logic resides in this folder and is split up by logical chunks:

    • config: Reading, modifying, validating and writing the JSON config file
    • constants: Constant values used across the tool
    • fixes: Some prompt related fixes (see #8)
    • git: Everything git command / config related
    • models: Model definition, User and Scope
    • utils: Small utility function used across the tool

    Breaking changes

    The following breaking change was introduced: The ability to use gitsu <alias> to immediatly set a user profile (see #10 and #5) is now available via the gitsu init <alias> command.

    New features

    gitsu now supports commands like:

    gitsu
    Use the arrow keys to navigate: ↓ ↑ → ← 
    Select action
      ▶ Select user
        Add new user
        Delete user
        Modify user
    

    gitsu select / gitsu s
    

    With this command the user can immediatly proceed to select an existing user profile. Same as using gitsu and selecting Select user


    gitsu add / gitsu a
    

    With this command the user can immediatly proceed to add a new user profile. Same as using gitsu and selecting Add new user


    gitsu delete / gitsu d
    

    With this command the user can immediatly proceed to delete an existing user profile. Same as using gitsu and selecting Delete user


    gitsu modify / gitsu m
    

    With this command the user can immediatly proceed to modify an existing user profile. Same as using gitsu and selecting Modify user


    gitsu reset / gitsu r
    The following 2 user profile(s) will be deleted 
      [foo]  Bar <[email protected]>
      [lazy] Dog <[email protected]>
    
    Use the arrow keys to navigate: ↓ ↑ → ← 
    Delete above profiles?
      ▶ Yes
        No
    

    With this command the user can reset / delete ALL existing user profiles. This closes #4

    Special alias 'default'

    With the special alias default the user can specify a default user profile which gets set when executing gitsu init without supplying an alias (see Breaking changes).

    New fields in User model

    Two new fields were added to the User model:

    • AddedAt: Timestamp when the profile was added
    • ModifiedAt: Timestamp when the profile was modified

    Currently these fields aren't used, but will allow for future improvements like history for example.

    Let me know what you think about this PR and if anything should be adjusted!

  • Add ability to name users, and change via command line

    Add ability to name users, and change via command line

    It would be ideal if we were able to give an alias for each user, and then change to that use via command line. For example:

    $ git su meow
    

    This would then set the git user and email associated with the alias meow.

  • DRY principle enforced to allow for greater code flexibility

    DRY principle enforced to allow for greater code flexibility

    To be precise, using a map to store all available commands and their string descriptions removes the necessity for a redundant switch statement that has to be manually updated with every new command. As a result, the run function is now more clear and concise.

  • Add gpg flag to prompt for a GPG key ID when adding a user

    Add gpg flag to prompt for a GPG key ID when adding a user

    Hi, thanks for the tool, it's really useful.

    I'd like to use the program to configure which GPG key should be used to sign commits for a given user. I've added this capability by prompting for a GPG key ID when the --gpg flag is specified. I don't know whether this is a feature you're interested in integrating, but if you are, I'm open to any feedback/suggestions.

    I thought it would be cool if the tool could display candidate keys in an interactive selection list, but integrating with the GPG keyring/agent seemed a bit complicated, so this PR just allows the key ID to be input as a string.

  • Fix issue when trying to modify user profiles

    Fix issue when trying to modify user profiles

    This PR introduces:

    • Optimized user profile selection and removing duplicate code
    • Fix issue while modifying user profiles

    Fix

    When trying to modify a user the changes were rejected because a user with the same alias already exists. This fixes the issue by looking at the index of the changed user. If we look at the same user we skip validation.

  • Fix issue #3

    Fix issue #3

    When adding / creating a new user, gitsu now checks if the user already exists in the config file.

    It does this by comparing the user name & mail address. If the check fails, gitsu exists with the error message Failed to add user: User Foo <[email protected]> already exists

    See #3

  • Add silent bell / bellskipper

    Add silent bell / bellskipper

    On Windows (and MacOS) the terminal bell is triggered when using the arrow keys to navigate the prompt. This disables the bell by providing a custom Stdout to the prompt which skips the bell character.

  • Fix an error with signing key on `gitsu select`

    Fix an error with signing key on `gitsu select`

    The previous logic does not check that err isn't nil before attempting a conversion to exec.ExitError.

    The output was

    $ gitsu select
    # select the correct user
    failed to set / unset user.signingkey option via git: : %!w(<nil>)
    exit status 1
    
Related tags
Switch between your git profiles easily
Switch between your git profiles easily

Git Profile Switcher Switch between your git profiles easily Install With Brew brew install theykk/tap/git-switcher With golang go get github.com/the

Dec 11, 2022
Git with a cup of tea, painless self-hosted git service
Git with a cup of tea, painless self-hosted git service

Gitea - Git with a cup of tea View the chinese version of this document Purpose The goal of this project is to make the easiest, fastest, and most pai

Jan 2, 2023
ReGit: A Tiny Git-Compatible Git Implementation written in Golang

ReGit is a tiny Git implementation written in Golang. It uses the same underlying file formats as Git. Therefore, all the changes made by ReGit can be checked by Git.

Oct 31, 2022
A Git RPC service for handling all the git calls made by GitLab
A Git RPC service for handling all the git calls made by GitLab

Quick Links: Roadmap | Want to Contribute? | GitLab Gitaly Issues | GitLab Gitaly Merge Requests | Gitaly is a Git RPC service for handling all the gi

Nov 13, 2021
Removes unnecessarily saved git objects to optimize the size of the .git directory.

Git Repo Cleaner Optimizes the size of the .git directory by removing all of the files that are unnecessarily-still-saved as part of the git history.

Mar 24, 2022
Git-now-playing - Git commits are the new AIM status messages

git-now-playing git-now-playing is an attempt to bring some of the panache of th

Apr 4, 2022
A command-line tool that makes git easier to use with GitHub.

hub is a command line tool that wraps git in order to extend it with extra features and commands that make working with GitHub easier. For an official

Jan 1, 2023
A tool to monitor git repositories and automatically pull & push changes

git-o-matic A tool to monitor git repositories and automatically pull & push changes Installation Packages & Binaries Arch Linux: gitomatic Binaries f

Dec 20, 2022
A Simple and Comprehensive Vulnerability Scanner for Container Images, Git Repositories and Filesystems. Suitable for CI
A Simple and Comprehensive Vulnerability Scanner for Container Images, Git Repositories and Filesystems. Suitable for CI

A Simple and Comprehensive Vulnerability Scanner for Containers and other Artifacts, Suitable for CI. Abstract Trivy (tri pronounced like trigger, vy

Jan 9, 2023
Simple git hooks written in go that installs globally to your machine

Go-hooks Simple git hooks written in go that installs globally to your machine Install curl -fsSL

Oct 19, 2022
🥄A simple generator for semantic git messages.

?? Tablespoon EXPERIMENTAL PREVIEW A simple generator for semantic git messages. Installation | Contributing Tablespoon is a simple generator which ca

Jul 22, 2022
Gogs is a painless self-hosted Git service
Gogs is a painless self-hosted Git service

Gogs - A painless self-hosted Git service 简体中文 ?? Vision The Gogs (/gɑgz/) project aims to build a simple, stable and extensible self-hosted Git servi

Jan 9, 2023
A highly extensible Git implementation in pure Go.
A highly extensible Git implementation in pure Go.

go-git is a highly extensible git implementation library written in pure Go. It can be used to manipulate git repositories at low level (plumbing) or

Jan 8, 2023
commit/branch/workdir explorer for git

gitin gitin is a commit/branch/status explorer for git gitin is a minimalist tool that lets you explore a git repository from the command line. You ca

Dec 31, 2022
SQL interface to git repositories, written in Go. https://docs.sourced.tech/gitbase

gitbase gitbase, is a SQL database interface to Git repositories. This project is now part of source{d} Community Edition, which provides the simplest

Dec 25, 2022
Fast and powerful Git hooks manager for any type of projects.
Fast and powerful Git hooks manager for any type of projects.

Lefthook The fastest polyglot Git hooks manager out there Fast and powerful Git hooks manager for Node.js, Ruby or any other type of projects. Fast. I

Jan 4, 2023
Implementation of git internals from scratch in Go language
Implementation of git internals from scratch in Go language

This project is part of a learning exercise to implement a subset of "git" commands. It can be used to create and maintain git objects, such as blobs, trees, commits, references and tags.

Nov 27, 2022
go mod vendor lets you check in your dependencies to git, but that's both bloaty (for developers) and tedious (remembering to update it).

go-mod-archiver Afraid of being unable to build historical versions of your Go program? go mod vendor lets you check in your dependencies to git, but

Dec 1, 2022
Quickly clone git repositories into a nested folders like GOPATH.

cl cl clones git repositories into nested folders like GOPATH and outputs the path of the cloned directory. Example: cl https://github.com/foo/bar Is

Nov 30, 2022