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 -v show version
``` ```
### run bash with default profile
```shell
gterm -arg "--rcfile" -arg <(gterm -profile)
```
## Install ## Install
```shell ```shell

View File

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

View File

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

13
main.js
View File

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

View File

@ -20,6 +20,12 @@ for PLATFORM in $PLATFORMS; do
echo "${CMD}" echo "${CMD}"
eval $CMD || FAILURES="${FAILURES} ${PLATFORM}" eval $CMD || FAILURES="${FAILURES} ${PLATFORM}"
sh -c "cd ${DIST} && tar -czf ${PROJ}-${VERSION}-${GOOS}-${GOARCH}.tar.gz ${BIN_FILENAME} && rm ${BIN_FILENAME}" 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 done
if [[ "${FAILURES}" != "" ]]; then 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>