feat: add default profile

master
Evan 2021-11-18 00:10:35 +08:00
parent 95bca77f37
commit deb22f8df1
8 changed files with 84 additions and 11 deletions

View File

@ -20,6 +20,12 @@ Usage: gterm [options]
-v show version
```
### run bash with default profile
```shell
gterm -arg "--rcfile" -arg <(gterm -profile)
```
## Install
```shell

View File

@ -5,36 +5,52 @@ import (
"fmt"
"net/http"
"os"
"strings"
"kumoly.io/lib/klog"
"kumoly.io/lib/ksrv"
"kumoly.io/tools/gterm"
)
type arrayFlags []string
func (i *arrayFlags) String() string {
return strings.Join(*i, ", ")
}
func (i *arrayFlags) Set(value string) error {
*i = append(*i, strings.TrimSpace(value))
return nil
}
var Version = "0.0.0"
var Build = "alpha"
var (
flagAllowIP string
flagAppName string = "gterm"
flagAppName string
flagAddr string
flagShell string
flagLogLevel int
flagDev bool
flagVer bool
flagArgs arrayFlags
flagProfile bool
)
func init() {
flag.StringVar(&flagAppName, "name", "gterm", "the application title")
flag.StringVar(&flagAddr, "addr", ":8000", "address to bind")
flag.StringVar(&flagShell, "shell", "bash", "the shell behind")
flag.Var(&flagArgs, "arg", "additional args to pass to cmd")
flag.BoolVar(&flagDev, "dev", false, "is development mode")
flag.IntVar(&flagLogLevel, "log-level", 9, "log level")
flag.StringVar(&flagAllowIP, "allow", "", "restrict ip")
flag.BoolVar(&flagProfile, "profile", false, "print default profile, invoked with <(..)")
flag.BoolVar(&flagVer, "v", false, "show version")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: gterm [options]\n")
fmt.Fprintf(os.Stderr, "Usage: gterm [options] [args...]\n")
flag.PrintDefaults()
}
}
@ -45,6 +61,10 @@ func main() {
fmt.Printf("%v - %v\n", Version, Build)
return
}
if flagProfile {
fmt.Println(gterm.BashProfile)
return
}
klog.LEVEL = klog.Llevel(flagLogLevel)
klog.PROD = !flagDev
@ -52,6 +72,8 @@ func main() {
g := gterm.New()
g.AppName = flagAppName
g.Cmd = flagShell
g.Args = flagArgs
fmt.Println(flagArgs.String())
server := &http.Server{
Addr: flagAddr,

View File

@ -22,6 +22,9 @@ import (
//go:embed public/index.html
var index string
//go:embed profile
var BashProfile string
var tmpl *engine.Engine
var servePublic = http.FileServer(http.FS(public.FS))

13
main.js
View File

@ -8,13 +8,12 @@ import 'xterm/css/xterm.css'
(function() {
const terminal = new Terminal({
// screenKeys: true,
// useStyle: true,
// cursorBlink: true,
// fullscreenWin: true,
// maximizeWin: true,
// screenReaderMode: true,
// cols: 128,
screenKeys: true,
useStyle: true,
cursorBlink: true,
fullscreenWin: true,
maximizeWin: true,
screenReaderMode: true,
});
const fitAddon = new FitAddon();
terminal.loadAddon(fitAddon);

View File

@ -20,6 +20,12 @@ for PLATFORM in $PLATFORMS; do
echo "${CMD}"
eval $CMD || FAILURES="${FAILURES} ${PLATFORM}"
sh -c "cd ${DIST} && tar -czf ${PROJ}-${VERSION}-${GOOS}-${GOARCH}.tar.gz ${BIN_FILENAME} && rm ${BIN_FILENAME}"
# build netgo ver
CMD="GOOS=${GOOS} GOARCH=${GOARCH} go build -tags netgo ${LDFLAGS} -o ${DIST}/${BIN_FILENAME} cmd/gterm/main.go"
eval $CMD
sh -c "cd ${DIST} && tar -czf ${PROJ}-${VERSION}-${GOOS}-${GOARCH}-netgo.tar.gz ${BIN_FILENAME} && rm ${BIN_FILENAME}"
done
if [[ "${FAILURES}" != "" ]]; then

37
profile Normal file
View File

@ -0,0 +1,37 @@
export BASH_CONF="bash_profile"
export LSCOLORS="gxfxcxdxbxegedabagacad"
export CLICOLOR=1
export TERM="xterm-256color"
PS1='\[\e[0;33m\]\u\[\e[0m\]@\[\e[0;32m\]\h\[\e[0m\]:\[\033[01;34m\]\W\[\033[00m\]$(git_info)\[\033[00m\]\n\[\033[1;31m\]\$ \[\033[00m\]'
# functions
function git_info {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return;
# Check for uncommitted changes in the index
if ! $(git diff --quiet --ignore-submodules --cached); then
uc=" $(tput setaf 64)+"
fi
# Check for unstaged changes
if ! $(git diff-files --quiet --ignore-submodules --); then
us=" $(tput setaf 124)!"
fi
# Check for untracked files
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
ut=" $(tput setaf 166)?"
fi
# Check for stashed files
if $(git rev-parse --verify refs/stash &>/dev/null); then
st=" $(tput setaf 136)$"
fi
echo " ($(tput bold)${ref#refs/heads/}$uc$us$ut$st$(tput sgr0)$(tput setaf 254))";
# echo "(${ref#refs/heads/})";
}
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
<!DOCTYPE html><html><head><link rel="stylesheet" href="index.6999253a.css"><title>{{.AppName}}</title><style>body::-webkit-scrollbar,div::-webkit-scrollbar,html::-webkit-scrollbar{display:none;width:0}body,html{margin:0;overflow:hidden;padding:0}div#terminal{height:100%;left:0;position:absolute;top:0;width:100%}div#terminal div{height:100%}.xterm-screen,.xterm-viewport{height:100%;margin:0;padding:0}</style></head><body> <div id="terminal"></div> <script type="module" src="index.52560dc1.js"></script> </body></html>
<!DOCTYPE html><html><head><link rel="stylesheet" href="index.6999253a.css"><title>{{.AppName}}</title><style>body::-webkit-scrollbar,div::-webkit-scrollbar,html::-webkit-scrollbar{display:none;width:0}body,html{margin:0;overflow:hidden;padding:0}div#terminal{height:100%;left:0;position:absolute;top:0;width:100%}div#terminal div{height:100%}.xterm-screen,.xterm-viewport{height:100%;margin:0;padding:0}</style></head><body> <div id="terminal"></div> <script type="module" src="index.4bd4d16a.js"></script> </body></html>