diff --git a/README.org b/README.org new file mode 100644 index 0000000..226220b --- /dev/null +++ b/README.org @@ -0,0 +1,58 @@ +#+title: gra +#+subtitle: Add new Git remotes quickly + + +/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=, + +#+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 + Usage: gra [OPTIONS] REMOTE_NAME + + 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 + + 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=. 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; diff --git a/gra b/gra index c820ffe..f213ebe 100755 --- a/gra +++ b/gra @@ -9,8 +9,8 @@ function print_usage { cat < /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 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}'"