Compare commits
10 commits
cbf64a2e14
...
5335adc901
| Author | SHA1 | Date | |
|---|---|---|---|
| 5335adc901 | |||
| 9904105c1a | |||
| e37c759f8d | |||
| 6dae691a92 | |||
| ce297e5fbe | |||
| a35486d801 | |||
| af1aecc3b5 | |||
| d45fb3d29d | |||
| 2a81e98fa7 | |||
| 6181b417f3 |
5 changed files with 97 additions and 9 deletions
58
README.org
Normal file
58
README.org
Normal file
|
|
@ -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=.
|
||||
4
flake.lock
generated
4
flake.lock
generated
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
16
gra
16
gra
|
|
@ -9,8 +9,8 @@ function print_usage {
|
|||
cat <<EOF
|
||||
Usage: gra [OPTIONS] REMOTE_NAME
|
||||
|
||||
Add a Git remote by providing a single name. Shorthands can be defined in
|
||||
~/.config/gra.config.
|
||||
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
|
||||
|
||||
|
|
@ -47,14 +47,18 @@ while (( "$#" )); do
|
|||
esac
|
||||
done
|
||||
|
||||
# Check missing argument
|
||||
[ "$remote_name" == "" ] && print_usage && exit 0
|
||||
|
||||
# TODO: Check if in Git repository
|
||||
# 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
|
||||
|
||||
|
|
|
|||
26
install.bash
Normal file
26
install.bash
Normal file
|
|
@ -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}'"
|
||||
Loading…
Add table
Add a link
Reference in a new issue