mirror of
				https://github.com/sammy-ette/Hilbish
				synced 2025-08-10 02:52:03 +00:00 
			
		
		
		
	Compare commits
	
		
			No commits in common. "17e12c8c2a93d0955c84cb417fd7660facbed678" and "7b0b06d9bf3d8304106a6830dfaa8a24d07cb4a4" have entirely different histories.
		
	
	
		
			17e12c8c2a
			...
			7b0b06d9bf
		
	
		
							
								
								
									
										6
									
								
								lua.go
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								lua.go
									
									
									
									
									
								
							@ -2,10 +2,10 @@ package main
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	hooks "hilbish/golibs/bait"
 | 
					 | 
				
			||||||
	cmds "hilbish/golibs/commander"
 | 
					 | 
				
			||||||
	lfs "hilbish/golibs/fs"
 | 
					 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
 | 
						lfs "hilbish/golibs/fs"
 | 
				
			||||||
 | 
						cmds "hilbish/golibs/commander"
 | 
				
			||||||
 | 
						hooks "hilbish/golibs/bait"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/yuin/gopher-lua"
 | 
						"github.com/yuin/gopher-lua"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										41
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								main.go
									
									
									
									
									
								
							@ -2,12 +2,11 @@ package main
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"io"
 | 
					 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"os/signal"
 | 
					 | 
				
			||||||
	"os/user"
 | 
						"os/user"
 | 
				
			||||||
 | 
						"os/signal"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
	hooks "hilbish/golibs/bait"
 | 
						hooks "hilbish/golibs/bait"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/akamensky/argparse"
 | 
						"github.com/akamensky/argparse"
 | 
				
			||||||
@ -17,21 +16,18 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const version = "0.4.0-dev.2+hilbiline"
 | 
					const version = "0.4.0-dev.2+hilbiline"
 | 
				
			||||||
 | 
					var l *lua.LState
 | 
				
			||||||
var (
 | 
					 | 
				
			||||||
	l *lua.LState
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// User's prompt, this will get set when lua side is initialized
 | 
					// User's prompt, this will get set when lua side is initialized
 | 
				
			||||||
	prompt string
 | 
					var prompt string
 | 
				
			||||||
	multilinePrompt = "> "
 | 
					var multilinePrompt = "> "
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	commands = map[string]bool{}
 | 
					// Map of builtin/custom commands defined in the commander lua module
 | 
				
			||||||
	aliases = map[string]string{}
 | 
					var commands = map[string]bool{}
 | 
				
			||||||
 | 
					// Command aliases
 | 
				
			||||||
	bait hooks.Bait
 | 
					var aliases = map[string]string{}
 | 
				
			||||||
	homedir string
 | 
					var bait hooks.Bait
 | 
				
			||||||
	running bool
 | 
					var homedir string
 | 
				
			||||||
)
 | 
					var running bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
	homedir, _ = os.UserHomeDir()
 | 
						homedir, _ = os.UserHomeDir()
 | 
				
			||||||
@ -73,9 +69,7 @@ func main() {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Set $SHELL if the user wants to
 | 
						// Set $SHELL if the user wants to
 | 
				
			||||||
	if *setshflag {
 | 
						if *setshflag { os.Setenv("SHELL", os.Args[0]) }
 | 
				
			||||||
		os.Setenv("SHELL", os.Args[0])
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// If user's config doesn't exixt,
 | 
						// If user's config doesn't exixt,
 | 
				
			||||||
	if _, err := os.Stat(defaultconfpath); os.IsNotExist(err) {
 | 
						if _, err := os.Stat(defaultconfpath); os.IsNotExist(err) {
 | 
				
			||||||
@ -131,18 +125,14 @@ func main() {
 | 
				
			|||||||
			for {
 | 
								for {
 | 
				
			||||||
				input, err = ContinuePrompt(strings.TrimSuffix(input, "\\"))
 | 
									input, err = ContinuePrompt(strings.TrimSuffix(input, "\\"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if err != nil || !strings.HasSuffix(input, "\\") {
 | 
									if err != nil || !strings.HasSuffix(input, "\\") { break }
 | 
				
			||||||
					break
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		running = true
 | 
							running = true
 | 
				
			||||||
		RunInput(input)
 | 
							RunInput(input)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		termwidth, _, err := term.GetSize(0)
 | 
							termwidth, _, err := term.GetSize(0)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil { continue }
 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		fmt.Printf("\u001b[7m∆\u001b[0m" + strings.Repeat(" ", termwidth - 1) + "\r")
 | 
							fmt.Printf("\u001b[7m∆\u001b[0m" + strings.Repeat(" ", termwidth - 1) + "\r")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -198,3 +188,4 @@ func HandleSignals() {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										21
									
								
								shell.go
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								shell.go
									
									
									
									
									
								
							@ -1,17 +1,18 @@
 | 
				
			|||||||
package main
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
	"bufio"
 | 
						"bufio"
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"os"
 | 
					 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/yuin/gopher-lua"
 | 
						"github.com/yuin/gopher-lua"
 | 
				
			||||||
	"layeh.com/gopher-luar"
 | 
						"layeh.com/gopher-luar"
 | 
				
			||||||
	"mvdan.cc/sh/v3/interp"
 | 
						"mvdan.cc/sh/v3/interp"
 | 
				
			||||||
	"mvdan.cc/sh/v3/syntax"
 | 
						"mvdan.cc/sh/v3/syntax"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func RunInput(input string) {
 | 
					func RunInput(input string) {
 | 
				
			||||||
@ -30,9 +31,7 @@ func RunInput(input string) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// If alias was found, use command alias
 | 
						// If alias was found, use command alias
 | 
				
			||||||
	if aliases[cmdArgs[0]] != "" {
 | 
						if aliases[cmdArgs[0]] != "" {
 | 
				
			||||||
		alias := aliases[cmdArgs[0]]
 | 
							cmdString = aliases[cmdArgs[0]] + strings.Trim(cmdString, cmdArgs[0])
 | 
				
			||||||
		cmdString = alias + strings.Trim(cmdString, cmdArgs[0])
 | 
					 | 
				
			||||||
		cmdArgs[0] = alias
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// If command is defined in Lua then run it
 | 
						// If command is defined in Lua then run it
 | 
				
			||||||
@ -50,9 +49,7 @@ func RunInput(input string) {
 | 
				
			|||||||
			fmt.Fprintln(os.Stderr,
 | 
								fmt.Fprintln(os.Stderr,
 | 
				
			||||||
			"Error in command:\n\n" + err.Error())
 | 
								"Error in command:\n\n" + err.Error())
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if cmdArgs[0] != "exit" {
 | 
							if cmdArgs[0] != "exit" { HandleHistory(cmdString) }
 | 
				
			||||||
			HandleHistory(cmdString)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -63,9 +60,7 @@ func RunInput(input string) {
 | 
				
			|||||||
		if syntax.IsIncomplete(err) {
 | 
							if syntax.IsIncomplete(err) {
 | 
				
			||||||
			for {
 | 
								for {
 | 
				
			||||||
				cmdString, err = ContinuePrompt(strings.TrimSuffix(cmdString, "\\"))
 | 
									cmdString, err = ContinuePrompt(strings.TrimSuffix(cmdString, "\\"))
 | 
				
			||||||
				if err != nil {
 | 
									if err != nil { break }
 | 
				
			||||||
					break
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				err = execCommand(cmdString)
 | 
									err = execCommand(cmdString)
 | 
				
			||||||
					if syntax.IsIncomplete(err) || strings.HasSuffix(input, "\\") {
 | 
										if syntax.IsIncomplete(err) || strings.HasSuffix(input, "\\") {
 | 
				
			||||||
					continue
 | 
										continue
 | 
				
			||||||
@ -80,9 +75,7 @@ func RunInput(input string) {
 | 
				
			|||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			if code, ok := interp.IsExitStatus(err); ok {
 | 
								if code, ok := interp.IsExitStatus(err); ok {
 | 
				
			||||||
				bait.Em.Emit("command.exit", code)
 | 
									bait.Em.Emit("command.exit", code)
 | 
				
			||||||
			} else {
 | 
								} else { fmt.Fprintln(os.Stderr, err) }
 | 
				
			||||||
				fmt.Fprintln(os.Stderr, err)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		bait.Em.Emit("command.exit", 0)
 | 
							bait.Em.Emit("command.exit", 0)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user