From 6181b417f383060492059f24aabb7f003abc61e3 Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Tue, 13 Aug 2024 21:56:25 +0200 Subject: [PATCH 01/10] list remotes if no argument is provided --- gra | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gra b/gra index c820ffe..06f7e26 100755 --- a/gra +++ b/gra @@ -10,7 +10,7 @@ function print_usage { Usage: gra [OPTIONS] REMOTE_NAME Add a Git remote by providing a single name. Shorthands can be defined in -~/.config/gra.config. +~/.config/gra.config. If no REMOTE_NAME is provided, all remotes get listed. REMOTE_NAME Name of the remote @@ -47,14 +47,18 @@ while (( "$#" )); do esac done -# Check missing argument -[ "$remote_name" == "" ] && print_usage && exit 0 - # TODO: Check if in Git repository if ! git status &> /dev/null; then error "Not inside a Git repository" fi +# Show remotes if no remote name was passed +if [ "$remote_name" == "" ]; then + echo -e "Argument ${text_bold}REMOTE_NAME${text_reset} not provided, listing remotes\n" + git remote -v + exit 0 +fi + # Read config [ -f ~/.config/gra.config ] && source ~/.config/gra.config From 2a81e98fa709879b1319579c5cc85fbf41f59a6b Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Tue, 13 Aug 2024 22:01:11 +0200 Subject: [PATCH 02/10] add install script --- install.bash | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 install.bash diff --git a/install.bash b/install.bash new file mode 100644 index 0000000..dc52a92 --- /dev/null +++ b/install.bash @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +# Adds $1 to ~/.bashrc if not already present +function _add_to_config { + if ! grep "$1" ~/.bashrc > /dev/null; then + echo "$1" >> ~/.bashrc + fi +} + +# Link files +basedir="$(dirname "$(realpath "$0")")" +mkdir -p ~/.local/{bin,share/bash-completion/completions} +ln -frs "${basedir}/gra" ~/.local/bin/gra +echo "Created link '~/.local/bin/gra'" +ln -frs "${basedir}/gra_completion.bash" ~/.local/share/bash-completion/completions/gra +echo "Created link '~/.local/share/bash-completion/completions/gra'" + +# Modify bashrc +touch ~/.bashrc +_add_to_config "export PATH=\$PATH:${HOME}/.local/bin" +_add_to_config "source ${HOME}/.local/share/bash-completion/completions/gra" +echo "Updated '~/.bashrc'" + +echo +echo "Source ~/.bashrc to use gra" +echo "To update gra in future execute 'git pull' in '${basedir}'" From d45fb3d29d839e2e803b8e95e6ba50ec6616876b Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Tue, 13 Aug 2024 22:12:06 +0200 Subject: [PATCH 03/10] adjust usage --- gra | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gra b/gra index 06f7e26..c167b98 100755 --- a/gra +++ b/gra @@ -9,8 +9,8 @@ function print_usage { cat < Date: Tue, 13 Aug 2024 22:15:56 +0200 Subject: [PATCH 04/10] add readme --- README.org | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 README.org diff --git a/README.org b/README.org new file mode 100644 index 0000000..cdf59c1 --- /dev/null +++ b/README.org @@ -0,0 +1,50 @@ +#+title: gra +#+subtitle: Add new Git remotes quickly + + +/gra/ (short for =git remote add=) is a small Bash script which quickly adds Git remotes. +New remote URLs will be added with the same URL scheme as the one of the =origin= remote. +The only argument which is needed is a =REMOTE_NAME=, + +* Usage + +#+begin_example + Usage: gra [OPTIONS] REMOTE_NAME + + Add a Git remote by providing a single name. If no REMOTE_NAME is provided, + all remotes get listed. + + REMOTE_NAME Name of the remote + + OPTIONS + -h, --help Show this help message and exit +#+end_example + +** Shorthands + +Shorthands can be defined in =~/.config/gra.config= for example like this: + +#+begin_src sh + ex=example + slu=SuperLongUsername +#+end_src + +They can be passed as =REMOTE_NAME= argument, which is handy for often-used, long remote names. +Autocompletion is available for all defined shorthands. + +* Installation + +** Manual + +Place the =gra= script in your =$PATH=. +To use the autocompletion feature source the =gra_completion.bash= script. + +** Script + +An installation script for Bash (=install.bash=) is provided which will link the two files to =~/.local/{bin/gra,share/bash-completion/completions/gra}= and add the corresponding entries to =~/.bashrc=. +Further updates of /gra/ require just =git pull=. + +** Nix Flake + +This repository is also a [[https://nixos.wiki/wiki/Flakes][Nix Flake]]. +/gra/ is provided as package under =github:Deleh/gra#gra=. From a35486d801b6e218f4240e4961b39b74e00987d7 Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Tue, 13 Aug 2024 22:21:54 +0200 Subject: [PATCH 05/10] adjust usage --- README.org | 4 ++-- gra | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.org b/README.org index cdf59c1..fd1cab1 100644 --- a/README.org +++ b/README.org @@ -11,8 +11,8 @@ The only argument which is needed is a =REMOTE_NAME=, #+begin_example Usage: gra [OPTIONS] REMOTE_NAME - Add a Git remote by providing a single name. If no REMOTE_NAME is provided, - all remotes get listed. + Add a Git remote by providing a single name. All remotes get listed If no + REMOTE_NAME is provided. REMOTE_NAME Name of the remote diff --git a/gra b/gra index c167b98..149c2d8 100755 --- a/gra +++ b/gra @@ -9,8 +9,8 @@ function print_usage { cat < Date: Tue, 13 Aug 2024 22:31:47 +0200 Subject: [PATCH 06/10] update flake --- flake.lock | 4 ++-- flake.nix | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index e09000a..a046407 100644 --- a/flake.lock +++ b/flake.lock @@ -3,8 +3,8 @@ "nixpkgs": { "locked": { "lastModified": 0, - "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", - "path": "/nix/store/2nnisw4pxbifisbkg58hrnis9ycs5ah1-source", + "narHash": "sha256-+CHVZnTnIYRLYsARInHYoWkujzcRkLY/gXm3s5bE52o=", + "path": "/nix/store/7840m01bg4qkhh3kq6mlrsi3s352qkc1-source", "type": "path" }, "original": { diff --git a/flake.nix b/flake.nix index 9b6c572..6aae464 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "Add new Git remotes quickly"; + description = "Add new Git remotes easily"; outputs = { self, nixpkgs }@inputs: let forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.platforms.unix; From 6dae691a924b3d53f2a488ea7e69f7e6321dfe0a Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Tue, 13 Aug 2024 22:44:39 +0200 Subject: [PATCH 07/10] update usage --- README.org | 2 +- gra | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.org b/README.org index fd1cab1..d8171d3 100644 --- a/README.org +++ b/README.org @@ -11,7 +11,7 @@ The only argument which is needed is a =REMOTE_NAME=, #+begin_example Usage: gra [OPTIONS] REMOTE_NAME - Add a Git remote by providing a single name. All remotes get listed If no + Add a Git remote by providing a single name. All remotes get listed if no REMOTE_NAME is provided. REMOTE_NAME Name of the remote diff --git a/gra b/gra index 149c2d8..ece9c31 100755 --- a/gra +++ b/gra @@ -9,7 +9,7 @@ function print_usage { cat < Date: Tue, 13 Aug 2024 22:46:19 +0200 Subject: [PATCH 08/10] update comment --- gra | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gra b/gra index ece9c31..f213ebe 100755 --- a/gra +++ b/gra @@ -47,7 +47,7 @@ while (( "$#" )); do esac done -# TODO: Check if in Git repository +# Check if in Git repository if ! git status &> /dev/null; then error "Not inside a Git repository" fi From 9904105c1a84c8e2f21397836d6e7247d9407bae Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Tue, 13 Aug 2024 22:48:58 +0200 Subject: [PATCH 09/10] update README --- README.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.org b/README.org index d8171d3..91f8415 100644 --- a/README.org +++ b/README.org @@ -2,7 +2,7 @@ #+subtitle: Add new Git remotes quickly -/gra/ (short for =git remote add=) is a small Bash script which quickly adds Git remotes. +/gra/ (short for =git remote add=) is a small Bash script which allows to add new Git remotes easily. New remote URLs will be added with the same URL scheme as the one of the =origin= remote. The only argument which is needed is a =REMOTE_NAME=, From 5335adc9010cea0e57f132e0aca48a8ad4ad8151 Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Tue, 13 Aug 2024 23:15:20 +0200 Subject: [PATCH 10/10] add example --- README.org | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.org b/README.org index 91f8415..226220b 100644 --- a/README.org +++ b/README.org @@ -6,6 +6,14 @@ New remote URLs will be added with the same URL scheme as the one of the =origin= remote. The only argument which is needed is a =REMOTE_NAME=, +#+begin_example + $ gra Deleh + Adding remote origin-Deleh with URL git@github.com:Deleh/example.git + Fetching from remote origin-Deleh + From github.com:Deleh/example + * [new branch] main -> origin-Deleh/main +#+end_example + * Usage #+begin_example