Compare commits
No commits in common. "5335adc9010cea0e57f132e0aca48a8ad4ad8151" and "cbf64a2e14b5696f8c6727a9a3e4dffeb9835586" have entirely different histories.
5335adc901
...
cbf64a2e14
5 changed files with 9 additions and 97 deletions
58
README.org
58
README.org
|
|
@ -1,58 +0,0 @@
|
||||||
#+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": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 0,
|
"lastModified": 0,
|
||||||
"narHash": "sha256-+CHVZnTnIYRLYsARInHYoWkujzcRkLY/gXm3s5bE52o=",
|
"narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=",
|
||||||
"path": "/nix/store/7840m01bg4qkhh3kq6mlrsi3s352qkc1-source",
|
"path": "/nix/store/2nnisw4pxbifisbkg58hrnis9ycs5ah1-source",
|
||||||
"type": "path"
|
"type": "path"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
description = "Add new Git remotes easily";
|
description = "Add new Git remotes quickly";
|
||||||
outputs = { self, nixpkgs }@inputs:
|
outputs = { self, nixpkgs }@inputs:
|
||||||
let
|
let
|
||||||
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.platforms.unix;
|
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.platforms.unix;
|
||||||
|
|
|
||||||
16
gra
16
gra
|
|
@ -9,8 +9,8 @@ function print_usage {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
Usage: gra [OPTIONS] REMOTE_NAME
|
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. Shorthands can be defined in
|
||||||
REMOTE_NAME is provided.
|
~/.config/gra.config.
|
||||||
|
|
||||||
REMOTE_NAME Name of the remote
|
REMOTE_NAME Name of the remote
|
||||||
|
|
||||||
|
|
@ -47,18 +47,14 @@ while (( "$#" )); do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Check if in Git repository
|
# Check missing argument
|
||||||
|
[ "$remote_name" == "" ] && print_usage && exit 0
|
||||||
|
|
||||||
|
# TODO: Check if in Git repository
|
||||||
if ! git status &> /dev/null; then
|
if ! git status &> /dev/null; then
|
||||||
error "Not inside a Git repository"
|
error "Not inside a Git repository"
|
||||||
fi
|
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
|
# Read config
|
||||||
[ -f ~/.config/gra.config ] && source ~/.config/gra.config
|
[ -f ~/.config/gra.config ] && source ~/.config/gra.config
|
||||||
|
|
||||||
|
|
|
||||||
26
install.bash
26
install.bash
|
|
@ -1,26 +0,0 @@
|
||||||
#!/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