Skip to content

Instantly share code, notes, and snippets.

@twlz0ne
Last active December 15, 2022 08:25
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save twlz0ne/5f5617e15c1a57e1d5c94ae94bb1d266 to your computer and use it in GitHub Desktop.
Save twlz0ne/5f5617e15c1a57e1d5c94ae94bb1d266 to your computer and use it in GitHub Desktop.
Launch emacs from emacs.d folder you placed anywhere.
#!/usr/bin/env bash
#
# Launch emacs from emacs.d folder you placed anywhere.
#
# @author gongqijian@gmail.com
# @created 2016-07-21
# @version 0.6
# @last-updated 2022-12-15 15:51:23 +0800
#
function usage {
cat<<EOF
Usage: $(basename $0) [emacs_path] [script_options] [-a emacs_arguments]
$(basename $0) [emacs_path] --exec shell_commands
Emacs path:
Path of emacs executable file, default is $(which emacs)
Options:
--help | -h Print help
--lang | -l LANG environment variable, default is en_US.UTF-8
--term | -t TERM environment variable, default is xterm
--argv | -a Arguments of emacs (default -nw --debug-init)
--exec Commands to execute (example: ./bin/doom sync)
Example:
git clone https://github.com/purcell/emacs.d emacs.d-purcell
cd emacs.d-purcell
$(basename $0) /Applications/Emacs.app/Contents/MacOS/Emacs -a -nw --debug-init
EOF
}
home_fake=$PWD
emacs_bin=emacs
opt_term=xterm
opt_lang=en_US.utf-8
opt_argv='-nw --debug-init'
opt_exec=
while [[ $# -gt 0 ]]; do
case $1 in
-*)
case $1 in
-h | --help) usage; exit 0;;
-l | --lang) shift; opt_lang=$1;;
-t | --term) shift; opt_term=$1;;
-a | --argv) shift; opt_argv="$@"; break;;
--exec) shift; opt_exec="$@"; break;;
*) echo Unknown option $1; usage; exit 1;;
esac
;;
*)
emacs_bin=$1
export EMACS=$1
;;
esac
shift
done
if [[ ! -e init.el ]] && [[ ! -e ./bin/doom ]]; then
cat <<EOF
init.el not found!
Please run $(basename $0) in an emacs.d folder.
EOF
exit 1
fi
if [[ ! -e ./.emacs.d ]]; then
ln -s . ./.emacs.d
fi
if [[ -e ~/.terminfo && ! -e ./.terminfo ]]; then
ln -snf ~/.terminfo ./.terminfo
fi
case $(uname -s) in
Darwin) ln -sf ~/Library ./Library
esac
if [[ -d .git ]]; then
mkdir -p .git/info
touch .git/info/exclude
if [[ -z $(grep -E '^\.emacs\.d$' .git/info/exclude) ]]; then
echo '.emacs.d' >> .git/info/exclude
fi
if [[ -z $(grep -E '^Library$' .git/info/exclude) ]]; then
echo 'Library' >> .git/info/exclude
fi
fi
export TERM=$opt_term
export LANG=$opt_lang
export HOME=$home_fake
if [[ -n "$opt_exec" ]]; then
$opt_exec
else
"$emacs_bin" $opt_argv
fi
@et2010
Copy link

et2010 commented Aug 18, 2017

@twlz0ne
Copy link
Author

twlz0ne commented Aug 18, 2017

@et2010 我竟然一年多没发现 -_-!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment