diff --git a/.github/release-nest-v3 b/.github/release-nest-v3 index d8263ee..56a6051 100644 --- a/.github/release-nest-v3 +++ b/.github/release-nest-v3 @@ -1 +1 @@ -2 \ No newline at end of file +1 \ No newline at end of file diff --git a/Makefile-v3 b/Makefile-v3 index 5608ce4..dcb1faf 100644 --- a/Makefile-v3 +++ b/Makefile-v3 @@ -3,5 +3,5 @@ all: install: mkdir -p $(DESTDIR)/usr/bin/ - GOAMD=v3 go build -ldflags="-s -w" -o $(DESTDIR)/usr/bin/falcon -buildvcs=false - chmod 755 $(DESTDIR)/usr/bin/falcon + GOAMD=v3 go build -ldflags="-s -w" -o $(DESTDIR)/usr/bin/carapace -buildvcs=false + chmod 755 $(DESTDIR)/usr/bin/carapace diff --git a/debian/changelog b/debian/changelog index 12554ca..a14af27 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,10 +1,4 @@ -falcon (1.0.2-101pika1) pika; urgency=low - - * Fix Intel - - -- Ward Nakchbandi Sat, 10 Dec 2022 13:48:00 +0300 - -falcon (1.0.1-101pika1) pika; urgency=low +carapace (1.0.7-101pika1) pika; urgency=low * Initial release diff --git a/debian/control b/debian/control index 0cfb97e..beabdf3 100644 --- a/debian/control +++ b/debian/control @@ -1,4 +1,4 @@ -Source: falcon +Source: carapace Section: admin Priority: optional Maintainer: ferreo @@ -8,11 +8,9 @@ Build-Depends: Standards-Version: 4.6.1 Homepage: https://pika-os.com -Package: falcon +Package: carapace Architecture: amd64 Depends: ${misc:Depends}, ${shlibs:Depends}, - util-linux, - power-profiles-daemon -Provides: falcon -Description: Accelerate your gaming experience with falcon, auto settting tasksets and choosing performance profiles +Provides: carapace +Description: A fast, extensible, fuzzy-search CLI completion tool diff --git a/go.mod b/go.mod deleted file mode 100644 index 5f724a8..0000000 --- a/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module falcon - -go 1.22 - -require golang.org/x/sync v0.8.0 diff --git a/go.sum b/go.sum deleted file mode 100644 index e584c1b..0000000 --- a/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= diff --git a/main.go b/main.go deleted file mode 100644 index 79c7735..0000000 --- a/main.go +++ /dev/null @@ -1,237 +0,0 @@ -package main - -import ( - "bufio" - "context" - "encoding/json" - "fmt" - "os" - "os/exec" - "path/filepath" - "sort" - "strconv" - "strings" - - "golang.org/x/sync/errgroup" -) - -type CPUInfo struct { - CPU int `json:"cpu"` - MaxMHz float64 `json:"maxmhz"` -} - -type LSCPUOutput struct { - CPUs []CPUInfo `json:"cpus"` -} - -type CoreFreq struct { - Core int - Freq int -} - -func main() { - args := os.Args[1:] - if len(args) == 0 { - fmt.Println("Please provide a command to run") - os.Exit(1) - } - - eg, ctx := errgroup.WithContext(context.Background()) - canPerf, cores, err := getBestCores() - if err != nil { - eg.Go(func() error { - return runCommand(ctx, false, []int{}, args) - }) - err = eg.Wait() - if err != nil { - fmt.Println(err) - os.Exit(1) - } - os.Exit(0) - } - - eg.Go(func() error { - return runCommand(ctx, canPerf, cores, args) - }) - err = eg.Wait() - if err != nil { - fmt.Println(err) - os.Exit(1) - } - os.Exit(0) -} - -func runCommand(ctx context.Context, canPerf bool, cores []int, args []string) error { - commandToRun := make([]string, 0) - if canPerf { - commandToRun = append(commandToRun, "powerprofilesctl", "launch", "-p", "performance") - } - - if len(cores) > 0 { - coreVals := make([]string, len(cores)) - for i, core := range cores { - coreVals[i] = fmt.Sprint(core) - } - - commandToRun = append(commandToRun, "taskset", "-c", strings.Join(coreVals, ",")) - } - - commandToRun = append(commandToRun, args...) - - cmd := exec.CommandContext(ctx, commandToRun[0], commandToRun[1:]...) - cmd.Env = append(cmd.Environ(), "POSIXLY_CORRECT=1") - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - cmd.Stdin = os.Stdin - - return cmd.Run() -} - -func getBestCores() (bool, []int, error) { - perfMode, amdPrefCores, amdFlag, highestCores, err := GetPPStatusAndHighestCores() - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - if !amdFlag { - return perfMode, highestCores, nil - } - - numAmdCores := len(amdPrefCores) - switch numAmdCores { - case 32: - return perfMode, getHighestCores(16, amdPrefCores), nil - case 24: - return perfMode, getHighestCores(12, amdPrefCores), nil - case 16: - return perfMode, getHighestCores(8, amdPrefCores), nil - default: - return perfMode, getHighestCores(numAmdCores, amdPrefCores), nil - } -} - -func getHighestCores(n int, coreFreqs []CoreFreq) []int { - if n <= 0 { - return []int{} - } - - sort.Slice(coreFreqs, func(i, j int) bool { - return coreFreqs[i].Freq > coreFreqs[j].Freq - }) - - result := make([]int, 0, n) - for i := 0; i < n && i < len(coreFreqs); i++ { - result = append(result, coreFreqs[i].Core) - } - sort.Stable(sort.IntSlice(result)) - - return result -} - -func GetPPStatusAndHighestCores() (bool, []CoreFreq, bool, []int, error) { - var ( - performanceMode bool - amdPstateFreqs []CoreFreq - amdFlag bool - highestCores []int - ) - - g, ctx := errgroup.WithContext(context.Background()) - g.Go(func() error { - cmd := exec.CommandContext(ctx, "powerprofilesctl", "list") - output, err := cmd.Output() - if err != nil { - performanceMode = false - return nil - } - - performanceMode = strings.Contains(string(output), "performance") - return nil - }) - - g.Go(func() error { - pattern := "/sys/devices/system/cpu/cpu*/cpufreq/amd_pstate_prefcore_ranking" - matches, err := filepath.Glob(pattern) - if err != nil { - return fmt.Errorf("failed to glob AMD pstate files: %w", err) - } - - if len(matches) > 0 { - amdFlag = true - } - - for _, match := range matches { - file, err := os.Open(match) - if err != nil { - return fmt.Errorf("failed to open file %s: %w", match, err) - } - defer file.Close() - - parts := strings.Split(match, "/") - cpuPart := parts[len(parts)-3] - coreNum, err := strconv.Atoi(strings.TrimPrefix(cpuPart, "cpu")) - if err != nil { - return fmt.Errorf("failed to parse core number from path %s: %w", match, err) - } - - scanner := bufio.NewScanner(file) - if scanner.Scan() { - value, err := strconv.Atoi(strings.TrimSpace(scanner.Text())) - if err != nil { - return fmt.Errorf("failed to parse value from file %s: %w", match, err) - } - - amdPstateFreqs = append(amdPstateFreqs, CoreFreq{Core: coreNum, Freq: value}) - } - - if err := scanner.Err(); err != nil { - return fmt.Errorf("error reading file %s: %w", match, err) - } - } - return nil - }) - - g.Go(func() error { - cmd := exec.CommandContext(ctx, "lscpu", "-e", "-J") - output, err := cmd.Output() - if err != nil { - return fmt.Errorf("failed to run lscpu command: %w", err) - } - - var lscpuOutput LSCPUOutput - if err := json.Unmarshal(output, &lscpuOutput); err != nil { - return fmt.Errorf("failed to unmarshal lscpu output: %w", err) - } - - sort.Slice(lscpuOutput.CPUs, func(i, j int) bool { - return lscpuOutput.CPUs[i].MaxMHz > lscpuOutput.CPUs[j].MaxMHz - }) - - if len(lscpuOutput.CPUs) > 0 { - topMHz := lscpuOutput.CPUs[0].MaxMHz - secondMHz := topMHz - - for _, cpu := range lscpuOutput.CPUs { - if cpu.MaxMHz < topMHz { - secondMHz = cpu.MaxMHz - break - } - } - - for _, cpu := range lscpuOutput.CPUs { - if cpu.MaxMHz == topMHz || cpu.MaxMHz == secondMHz { - highestCores = append(highestCores, cpu.CPU) - } - } - } - - return nil - }) - - if err := g.Wait(); err != nil { - return false, nil, false, nil, err - } - - return performanceMode, amdPstateFreqs, amdFlag, highestCores, nil -} diff --git a/main.sh b/main.sh index 459edbc..b009a44 100755 --- a/main.sh +++ b/main.sh @@ -2,16 +2,17 @@ set -e -VERSION="1.0.2" +VERSION="1.0.7" source ./pika-build-config.sh echo "$PIKA_BUILD_ARCH" > pika-build-arch # Clone Upstream -mkdir -p ./falcon -cp -rvf ./* ./falcon || true -cd ./falcon +git clone https://github.com/carapace-sh/carapace-bin.git -b v"$VERSION" ./carapace +cp -rvf ./debian ./carapace/ +cp -rvf ./Makefile-v3 ./carapace/Makefile +cd ./carapace # Get build deps apt-get build-dep ./ -y