Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tw-yshuang committed Dec 14, 2022
2 parents eafb271 + 03b9b7d commit 0471cd6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
# Git_SSH-Account_Switch

A CLI tool can switch ssh account to your current shell. You will easily switch to your git account & ssh key when using the server, and using your account to manipulate the project on the server.

**NOTE**: This tool is for the user who using `Zsh` on the UNIX/Linux platfrom.

## Installation

```shell
$ bash ./setup.sh
```

it will add some code in your `profile` & `$logout_profile`, and setup `git-acc` & `.gitacc` on the `$HOME`. \
file:

> git-acc.sh -> $HOME/.git-acc, `git-acc` function.\
> .gitacc -> $HOME/.gitacc, save info. that regist on `git-acc`.
> .gitacc -> $HOME/.gitacc, save info. that regist on `git-acc`.
## Control

```shell
+---------------+
| git-acc |
Expand All @@ -25,7 +32,7 @@ OPTIONS
[account] use which accounts on this shell, type the account name that you register.
-h, --help print help information.
-add, --add_account build git_account info. & ssh-key.
-t, --type ssh-key types, follow `ssh-keygen` rule,
-t, --type ssh-key types, follow `ssh-keygen` rule,
types: dsa | ecdsa | ecdsa-sk | ed25519 | ed25519-sk | rsa(default)
-rm, --remove_account remove git_account info. & ssh-key from this device
-out, --logout logout your current ssh-acc.
Expand All @@ -37,56 +44,72 @@ EXAMPLES
```

### SWITCH ACCOUNT

When you want to use the account that you have already added it, you can type:

```shell
$ git-acc <tab>
```

Then it will come out the current account that registers in the `git-acc` to let you choose, e.g.

```shell
$ git-acc <tab>
tw-yshuang cool-name ...
```

### ADD

```shell
$ git-acc -add
or
$ git-acc --add_account
```

It will ask you to type:

```shell
Enter your git user name: <acc_name>
Enter your git user mail: <acc_mail>
```

After that, `git-acc` will generate `id_rsa_<acc_name>`, `id_rsa_<acc_name>.pub` in the `$HOME/.ssh`. \
Next, you can type `$ git-acc <acc_name>`, to login your account.\
NOTE: You also can overwrite your account.

#### **CHOOSE YOUR SSH-KEY TYPE**

If you do not want to use `rsa` type to create your ssh-key, you can use this:

```shell
$ git-acc -add -t <key-type>
or
$ git-acc -add --type <key-type>
```

This args is following `ssh-keygen -t` rule, you can type corresponding key type you wnat! \
Types: `dsa | ecdsa | ecdsa-sk | ed25519 | ed25519-sk | rsa(default)`

### REMOVE

```shell
$ git-acc -rm
or
$ git-acc --remove_account
```

It will ask you to type:

```shell
Enter the git user name you want to remove: <acc_name>
```

### LOGOUT

```shell
$ git-acc -out
or
$ git-acc --logout
$ git-acc --logout
```
Logout your ssh-acc perfectly at CLI mode.

Logout your ssh-acc perfectly at CLI mode.
4 changes: 2 additions & 2 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env zsh

function Echo_Color(){
case $1 in
Expand Down Expand Up @@ -61,5 +61,5 @@ if ! [ -f ~/.gitacc ]; then
printf "" >> ~/.gitacc
fi

source $HOME/.git-acc
source $profile
echo "Done!! Now can use! Enjoy~~~"
15 changes: 15 additions & 0 deletions uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env zsh

# remove ~/.zlogout code that related with git-acc
match=$(grep -nF "$(cat ./logout.script)" ~/.zlogout | cut -f1 -d:)
vi +"$(echo $match | head -n1),$(echo $match | tail -n1)d" +wq ~/.zlogout

# remove ~/.zlogout code that related with git-acc
gitacc_config='# git account switch
source $HOME/.git-acc'
match=$(grep -nF $gitacc_config ~/.zshrc | cut -f1 -d:)
vi +"$(echo $match | head -n1),$(echo $match | tail -n1)d" +wq ~/.zshrc

# remove .git-acc .gitacc
rm ~/.git-acc
rm ~/.gitacc

0 comments on commit 0471cd6

Please sign in to comment.