Last active
May 25, 2020 08:10
-
-
Save aeghn/1c098ce006f39896b271d35d82ee2d1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DIR="$HOME/repos/memacs" | |
export SHELL=$(which bash) | |
start(){ | |
local name="$1" | |
cd $DIR | |
echo -e "> booting $name Emacs" | |
HOME="$DIR/$name" emacs | |
} | |
show_help(){ | |
cat <<EOF | |
memacs -- multi emacs selector | |
-m LINK -- make new entry | |
-h -- show this help | |
EOF | |
} | |
create(){ | |
local link user yon name | |
link="$1" | |
name=${link##*/} | |
if [[ "$name" =~ ^(\.?emacs\.d)|(\..*)$ ]]; then | |
echo -e "> The repo is like ^(\.?emacs\.d)|(\..*)$\n> try to use the user name" | |
name="${link%/*}" | |
name="${name##*/}" | |
fi | |
echo -e "> Would you like to use \`$name' as name to config:\n\t$link" | |
read -p " y or n: " yon | |
if [ ${yon:-"y"} == "n" ];then | |
read -p "> Input name manually: " name | |
fi | |
while [ -d "$DIR/$name" ]; do | |
echo -e "> $DIR/$name already existed." | |
read -p " Input name manually: " name | |
done | |
mkdir -p "$DIR/$name" | |
proxychains -q git clone "$link" "$DIR/$name/emacs.d" | |
ln -s "$DIR/$name/emacs.d" "$DIR/$name/.emacs.d" | |
} | |
select_config() { | |
local configs sn | |
configs=($(ls $DIR)) | |
for i in ${!configs[@]}; do | |
printf "%s: %s\n" "$i" "${configs[$i]}" | |
done | |
read -p "Select one: " sn | |
start ${configs[$sn]} | |
} | |
if [ $# -eq 0 ];then | |
select_config | |
else | |
while getopts "lc:m:hs:" opt ;do | |
case $opt in | |
c) start "$OPTARG" ;; | |
h) showHelp ;; | |
m) create "${OPTARG}" ;; | |
esac | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment