-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path9a
executable file
·129 lines (115 loc) · 3.67 KB
/
9a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env sh
# launch script for plan9port's Acme text editor
if [ -z "$PLAN9" ] && command -v 9 >/dev/null 2>&1; then
export PLAN9="$(9 sh -c 'echo $PLAN9')"
[ ! -z "$PLAN9" ] && export PATH=$PATH:$PLAN9/bin
fi
if [ -z "$PLAN9" ]; then
echo "error: PLAN9 not defined, was plan9port installed?" 1>&2
exit 1
fi
# Run acme via absolute path, in case there is another acme in the PATH.
acme="$PLAN9/bin/acme"
if [ ! -x "$acme" ]; then
echo "error: $acme not found, was plan9port installed?" 1>&2
exit 1
fi
usage() {
echo "usage: $0 [-fi9] [-c ncol] [-t tab_stop] [file ...]" 1>&$1
echo "Launch the Acme text editor." 1>&$1
echo "Use -f to have a proportional font as the primary font." 1>&$1
# -i option implemented by https://github.com/ixtenu/plan9port/commit/6146ab0734c5
echo "Use -i to enable Spaces ON at start up (requires patched Acme)." 1>&$1
echo "Use -9 to put \$PLAN9/bin at the front of \$PATH." 1>&$1
echo "Use -c ncol to set the initial number of columns (default 2)." 1>&$1
echo "Use -t tab_stop to customize distance between tab stops (default 4)." 1>&$1
exit $(($1 - 1))
}
tabstop=4
fopt=0
nine=
aopts="-a" # always run with -a (equivalent to executing "Indent ON")
ncol=2
while getopts fi9c:t:h name; do
case $name in
f) fopt=1;;
i) aopts="$aopts -i";;
9) nine='9';;
c) ncol=$OPTARG;;
t) tabstop=$OPTARG;;
h) usage 1;;
?) usage 2;;
esac
done
shift $(($OPTIND - 1))
aopts="$aopts -c $ncol"
# add the directory containing this script to the PATH so that other
# Acme-specific scripts in the same directory will be available within Acme
bindir="$(cd -- "$(dirname $(readlink -f "$0"))" >/dev/null 2>&1 && pwd -P)"
export PATH="$bindir:$PATH"
# rc is Plan 9's shell
export SHELL=rc
export acmeshell=rc
# distance between tab stops (set above)
export tabstop
# Acme's win terminal doesn't do colors, bold, etc.
export TERM=dumb
export CLICOLOR=0
export NO_COLOR=1
# nobs removes backspaces from man pages
export PAGER=nobs
# E opens in Acme and waits for Put. If git config core.editor is unset,
# this suffices for git commit to open an Acme window.
export EDITOR=E
browsers='librewolf firefox brave netsurf netsurf-gtk'
for b in $browsers; do
if command -v $b >/dev/null 2>&1; then
export BROWSER=$b
break
fi
done
if [ ! "$(pgrep '^plumber$')" ]; then
echo starting plumber
"$PLAN9"/bin/plumber
fi
# Preferred proportional and monospace fonts. Note that Acme will fail to
# launch if its primary font isn't available.
#
# To review the available fonts:
# fontsrv &
# 9p ls font | less
# fg
# ^C
#
# Default to fonts which are available out-of-the-box on common Linux distros.
font_prop='/mnt/font/LiberationSans/13a/font'
font_mono='/mnt/font/Hack-Regular/11a/font'
# Use Cascadia Code as the monospace font, if available.
if command -v fc-list >/dev/null 2>&1; then
if fc-list | grep -q 'CascadiaCode-Regular\.ttf'; then
font_mono='/mnt/font/CascadiaCode-Regular/12a/font'
fi
fi
if [ $fopt -eq 0 ]; then
# By default, use a monospace font as the primary font and a
# proportional font as the secondary font: the reverse of the usual
# convention for Acme. I do this because I work on projects which
# (unfortunately) make heavy use of spaces for alignment and that
# requires a monospace font to display correctly.
font1=$font_mono
font2=$font_prop
else
font1=$font_prop
font2=$font_mono
fi
files="$@"
# always open $HOME/bookmark, if it exists
if [ -r "$HOME/bookmark" ]; then
if [ -z "$files" ]; then
# open $PWD as Acme does by default when no files are given
files="$(readlink -f "$PWD")"
fi
files="$files $(readlink -f "$HOME/bookmark")"
fi
# Suppress error messages (might want to remove this for debugging).
$nine $acme $aopts -f $font1 -F $font2 $files 2>/dev/null &