File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ # -*- coding: UTF-8 -*-
3+ # # Helper script to speed up ssh keys generation for services like gitlab and github
4+ # # options
5+ # # -n, --name <string> Private key name [default: id_rsa]
6+ # # -e, --email <string> Email to associate with the key
7+ # GENERATED_CODE: start
8+ # Default values
9+ _name=id_rsa
10+
11+ # No-arguments is not allowed
12+ [ $# -eq 0 ] && sed -ne ' s/^## \(.*\)/\1/p' $0 && exit 1
13+
14+ # Converting long-options into short ones
15+ for arg in " $@ " ; do
16+ shift
17+ case " $arg " in
18+ " --name" ) set -- " $@ " " -n" ;;
19+ " --email" ) set -- " $@ " " -e" ;;
20+ * ) set -- " $@ " " $arg "
21+ esac
22+ done
23+
24+ function print_illegal() {
25+ echo Unexpected flag in command line \" $@ \"
26+ }
27+
28+ # Parsing flags and arguments
29+ while getopts ' hn:e:' OPT; do
30+ case $OPT in
31+ h) sed -ne ' s/^## \(.*\)/\1/p' $0
32+ exit 1 ;;
33+ n) _name=$OPTARG ;;
34+ e) _email=$OPTARG ;;
35+ \? ) print_illegal $@ >&2 ;
36+ echo " ---"
37+ sed -ne ' s/^## \(.*\)/\1/p' $0
38+ exit 1
39+ ;;
40+ esac
41+ done
42+ # GENERATED_CODE: end
43+
44+ set -xe
45+
46+ cd $HOME /.ssh
47+
48+ ssh-keygen -o -t rsa -b 4096 -C " $_email " -f $_name
49+
50+ cd -
51+
52+ xclip -sel clip < $HOME /.ssh/$_name .pub
You can’t perform that action at this time.
0 commit comments