Compare commits

...

21 Commits

Author SHA1 Message Date
Tobias P.L Wennberg
ada7fa9d9e fix cursor 2025-01-14 09:24:56 +01:00
Tobias P.L Wennberg
3f1b876f68 Fix merge with autocomplete, still a few quirks 2025-01-14 09:15:35 +01:00
Tobias P.L Wennberg
78fb97a860 Nvim works! 2025-01-14 09:02:59 +01:00
Tobias P.L Wennberg
e37798dd82 merge conflict 2025-01-13 18:05:13 +01:00
Tobias P.L Wennberg
a227e3e106 remove api key 2025-01-13 18:03:45 +01:00
markstad
94425a8c94 brainrot har implementerats 2025-01-13 17:58:00 +01:00
Lo
2f6f75b3a4 Mindre fixar med auto slut 2025-01-13 17:46:40 +01:00
Tobias P.L Wennberg
0216b72d65 Accidentally disabled tab-complete 2025-01-13 17:12:54 +01:00
Tobias P.L Wennberg
35af0423a7 merge flodman 2025-01-13 17:04:15 +01:00
Tobias P.L Wennberg
3c166dda98 Merge branch 'Flodman' 2025-01-13 17:02:51 +01:00
In_the_Thick_of_It
e6e223b6a7 implemented some brainrot for y'all :):):):):):) 2025-01-13 16:59:09 +01:00
Tobias P.L Wennberg
d4757c154b Fix 2025-01-13 15:45:26 +01:00
Tobias P.L Wennberg
45cf77ed2a Merge fix 2025-01-13 15:39:04 +01:00
Lo
45f50a95ce History auto komplett :D 2025-01-13 15:28:58 +01:00
Laukka
0525f346b4 Merge remote-tracking branch 'origin/laukkasBranch' into laukkasBranch 2025-01-13 15:01:43 +01:00
Laukka
15da22bc16 added fritiofscommando och att man kan ha " " innan komandon 2025-01-13 15:01:38 +01:00
Laukka
642d1780b6 added fritiofscommando och att man kan ha " " innan komandon 2025-01-13 14:37:35 +01:00
Laukka
2932f9bf43 added fritiofscommando och att man kan ha " " innan komandon 2025-01-13 14:28:15 +01:00
Laukka
6c63fc7122 Merge branch 'refs/heads/master' into laukkasBranch
# Conflicts:
#	input_parser/input_parser.go
2025-01-13 14:25:54 +01:00
Tobias P.L Wennberg
a545c4cab3 Upp och ned pil är konstiga, väntar på hansons pil implementation innan jag fixar 2025-01-13 14:17:31 +01:00
Laukka
aad4da3077 fixed len 1 and 0 args and flags 2025-01-13 10:55:44 +01:00
13 changed files with 223 additions and 25 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
./api/api.go

6
api/api.go Normal file
View File

@ -0,0 +1,6 @@
package api
func Api() string {
apiString := "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"
return apiString
}

View File

@ -0,0 +1,42 @@
package brainrot
import (
"bbash/api"
"bbash/environment"
"bbash/input_parser"
"context"
"fmt"
"os"
"path/filepath"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
func Brainrot(in input_parser.Input, env *environment.Env) {
file := filepath.Join(env.Path, in.Args_raw)
bytea_str, err := os.ReadFile(file)
//Skicka string(bytea_str)
if err != nil {
fmt.Print(fmt.Sprintf("L Rizz", err.Error()))
return
}
//Send to chatgpt
client := openai.NewClient(
option.WithAPIKey(api.Api()), // defaults to os.LookupEnv("OPENAI_API_KEY")
)
prompt := fmt.Sprintf("Rewrite the text I will provide you to brainrot. Make sure to use some of the words skibidi gyatt rizz only in ohio duke dennis did you pray today livvy dunne rizzing up baby gronk sussy imposter pibby glitch in real life sigma alpha omega male grindset andrew tate goon cave freddy fazbear colleen ballinger smurf cat vs strawberry elephant blud dawg shmlawg ishowspeed a whole bunch of turbulence ambatukam bro really thinks he's carti literally hitting the griddy the ocky way kai cenat fanum tax garten of banban no edging in class not the mosquito again bussing axel in harlem whopper whopper whopper whopper 1 2 buckle my shoe goofy ahh aiden ross sin city monday left me broken quirked up white boy busting it down sexual style goated with the sauce john pork grimace shake kiki do you love me huggy wuggy nathaniel b lightskin stare biggest bird omar the referee amogus uncanny wholesome reddit chungus keanu reeves pizza tower zesty poggers kumalala savesta quandale dingle glizzy rose toy ankha zone thug shaker morbin time dj khaled sisyphus oceangate shadow wizard money gang ayo the pizza here PLUH nair butthole waxing t-pose ugandan knuckles family guy funny moments compilation with subway surfers gameplay at the bottom nickeh30 ratio uwu delulu opium bird cg5 mewing fortnite battle pass all my fellas gta 6 backrooms gigachad based cringe kino redpilled no nut november pokénut november foot fetish F in the chat i love lean looksmaxxing gassy social credit bing chilling xbox live mrbeast kid named finger better caul saul i am a surgeon hit or miss i guess they never miss huh i like ya cut g ice spice gooning fr we go gym kevin james josh hutcherson coffin of andy and leyley metal pipe falling. Rewrite this text: %s", string(bytea_str))
chatCompletion, err := client.Chat.Completions.New(context.TODO(), openai.ChatCompletionNewParams{
Messages: openai.F([]openai.ChatCompletionMessageParamUnion{
openai.UserMessage(prompt),
}),
Model: openai.F(openai.ChatModelGPT4oMini),
})
if err != nil {
panic(err.Error())
}
fmt.Print(chatCompletion.Choices[0].Message.Content)
}

View File

@ -1,10 +1,12 @@
package command
import (
"bbash/command/brainrot"
"bbash/command/cat"
"bbash/command/cd"
"bbash/command/cp"
"bbash/command/echo"
"bbash/command/fritiofcommand"
"bbash/command/head"
"bbash/command/help"
"bbash/command/ls"
@ -14,6 +16,7 @@ import (
"bbash/command/rm"
"bbash/command/tail"
"bbash/command/touch"
"bbash/command/whereareyou"
"bbash/environment"
"bbash/input_parser"
"fmt"
@ -33,6 +36,8 @@ func Init(env *environment.Env) {
func Run_command(in input_parser.Input, env *environment.Env) {
switch in.Instruction {
case "fritiofcommand":
fritiofcommand.Fritiof(in, env)
case "pwd":
pwd.Pwd(in, env)
case "echo":
@ -59,6 +64,10 @@ func Run_command(in input_parser.Input, env *environment.Env) {
help.Help(in, env)
case "tail":
tail.Tail(in, env)
case "whereareyou":
whereareyou.Whereareyou(in, env)
case "brainrot":
brainrot.Brainrot(in, env)
default:
if !run_by_path(in, env) {
fmt.Println(fmt.Sprintf("No such command! (%s)", in.Instruction))
@ -73,8 +82,13 @@ func run_by_path(in input_parser.Input, env *environment.Env) bool {
return false
}
cmd := exec.Command(instr, strings.Fields(in.Args_raw)...)
output, _ := cmd.CombinedOutput()
print(string(output))
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
if err := cmd.Run(); err != nil {
fmt.Println(err.Error())
}
//output, _ := cmd.CombinedOutput()
//print(string(output))
return true
}

View File

@ -0,0 +1,12 @@
package fritiofcommand
import (
"bbash/environment"
"bbash/input_parser"
"fmt"
)
func Fritiof(in input_parser.Input, _ *environment.Env) {
fmt.Print("Sannolikheten för läkarlinjen är mycket hög!")
// fritiof
}

View File

@ -0,0 +1,11 @@
package whereareyou
import (
"bbash/environment"
"bbash/input_parser"
"fmt"
)
func Whereareyou(in input_parser.Input, env *environment.Env) {
fmt.Println("You're in the thick of it everybody knows!")
}

5
go.mod
View File

@ -3,6 +3,11 @@ module bbash
go 1.23.4
require (
github.com/openai/openai-go v0.1.0-alpha.44 // indirect
github.com/tidwall/gjson v1.18.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/term v0.28.0 // indirect
)

12
go.sum
View File

@ -1,3 +1,15 @@
github.com/openai/openai-go v0.1.0-alpha.44 h1:p0OZp+sGEBcKlCIjEWIO5+R3cZEz34C3iw/MM5gAHoo=
github.com/openai/openai-go v0.1.0-alpha.44/go.mod h1:3SdE6BffOX9HPEQv8IL/fi3LYZ5TUpRYaqGQZbyk11A=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=

18
hello Normal file
View File

@ -0,0 +1,18 @@
a
b
c
1
2
3
4
5
6
7
8
9
9
9
9
9
9
9

View File

@ -12,13 +12,18 @@ func AutoComplete(input string) string {
return input
}
if tabIndex+2 > len(commandsTab) {
tabIndex = -1
}
if prevInput == input {
tabIndex = tabIndex + 1
if len(commandsTab) == 0 && tabIndex > 0 {
return input
}
if tabIndex > len(commandsTab)-1 {
tabIndex = 0
}
prevInput = commandsTab[tabIndex]
return commandsTab[tabIndex]
}
@ -31,6 +36,8 @@ func AutoComplete(input string) string {
"cd",
"cp",
"echo",
"exit",
"fritiofcommand",
"head",
"help",
"ls",
@ -40,11 +47,16 @@ func AutoComplete(input string) string {
"rm",
"tail",
"touch",
"whereareyou",
}
var commandsWorking []string
// println(commandsWorking)
for _, currentCommand := range currentCommands {
// println("currentCommand")
// println(currentCommand)
if len(currentCommand) < inputLength {
continue
@ -57,6 +69,7 @@ func AutoComplete(input string) string {
}
commandsWorking = append(commandsWorking, currentCommand)
}
commandsTab = commandsWorking

View File

@ -0,0 +1,55 @@
package input_parser
import "bbash/environment"
func AutoCompleteHistory(input string, env environment.Env) string {
inputLength := len(input)
if inputLength == 0 {
return ""
}
// tabIndex = 0
// currentCommands := []string{
// "cat",
// "cd",
// "cp",
// "echo",
// "head",
// "help",
// "ls",
// "man",
// "mv",
// "pwd",
// "rm",
// "tail",
// "touch",
// }
historyWorking := ""
for _, currentHistory := range env.History[:len(env.History)-1] {
// println("currentHistory", currentHistory)
if len(currentHistory) < inputLength {
continue
}
currentCommandWithoutEnd := currentHistory[:inputLength]
if currentCommandWithoutEnd != input {
continue
}
historyWorking = currentHistory
}
if len(historyWorking) != 0 {
historyWorking = historyWorking[inputLength:]
}
return historyWorking
}

View File

@ -20,6 +20,7 @@ func Escape_handler(reader *bufio.Reader, history_index int, input string, env e
if history_index > 0 {
history_index--
input = env.History[history_index]
cursor = len(input)
}
case 66: //B
if history_index < len(env.History)-1 {
@ -30,12 +31,17 @@ func Escape_handler(reader *bufio.Reader, history_index int, input string, env e
input = ""
cursor = 0
}
cursor = len(input)
case 68: //D
if cursor > 0 {
cursor--
}
case 67: //C
if prevGhostString != "" {
input = input + prevGhostString
cursor = len(input)
}
if cursor < len(input) {
cursor++
}

View File

@ -10,6 +10,8 @@ import (
"golang.org/x/term"
)
var prevGhostString string
type Input struct {
// The instruction a.k.a first argument
Instruction string
@ -22,10 +24,10 @@ type Input struct {
func Parse(env *environment.Env) Input {
input := input_str(env)
return parse_input(input)
return Parse_input(input)
}
func parse_input(input string) Input {
split := strings.Split(string(input), " ")
func Parse_input(input string) Input {
split := strings.Split(strings.TrimSpace(string(input)), " ")
instruction := strings.TrimSpace(split[0])
args_raw := ""
@ -36,14 +38,11 @@ func parse_input(input string) Input {
var flags []string
var args []string
for _, arg := range split[1:] {
if len(arg) == 0 {
continue
} else if len(arg) == 1 {
if len(arg) == 1 {
if arg[0] == '-' {
continue
} else {
args = append(args, strings.TrimSpace(arg))
}
_ = append(args, string(arg[0]))
} else if arg[0:2] == "--" {
var result = strings.TrimSpace(arg)
flags = append(flags, string(result[2:]))
@ -89,23 +88,21 @@ func input_str(env *environment.Env) string {
for {
r_rune, _, err := reader.ReadRune()
if err != nil {
fmt.Print(fmt.Sprintf("Error reading user input: ", err.Error()))
fmt.Print(fmt.Sprintf("Error reading user input: %s", err.Error()))
}
switch r_rune {
case 3: // ^C
fmt.Println("^C")
cursor = 0
input = ""
case 4: // ^D
input = "exit"
goto loop_exit
case 9: // Tab
case 9: // TAB
input = AutoComplete(input)
cursor = len(input)
case 27: // Escape
input, history_index, cursor = Escape_handler(reader, history_index, input, *env, cursor)
case 127: //packspace
if len(input) > 0 {
input = input[:len(input)-1]
@ -117,16 +114,22 @@ func input_str(env *environment.Env) string {
cursor++
input = input + string(r_rune)
}
ghost_input := AutoCompleteHistory(input, *env)
env.History[len(env.History)-1] = input
//fmt.Println(r_rune)
fmt.Print("\r")
// fmt.Print("\r\033[K")
fmt.Print(env.Path)
fmt.Print(" > ")
fmt.Print("\033[K")
fmt.Print(" > \033[K")
fmt.Print(input)
fmt.Print("\033[2m", ghost_input, "\033[0m")
prevGhostString = ""
backwardSteps := len(ghost_input)
if backwardSteps != 0 {
fmt.Printf("\033[%dD", backwardSteps)
prevGhostString = ghost_input
}
fmt.Print("\r")
fmt.Print(env.Path)
fmt.Print(" > ")