Skip to content

Commit

Permalink
Merge pull request #2 from wrype/opti-path-display
Browse files Browse the repository at this point in the history
optimize path display on Windows
  • Loading branch information
Kacifer authored Jul 27, 2023
2 parents b3e58cc + ff554a0 commit c644205
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ require (
github.com/muesli/termenv v0.8.1
github.com/pkg/errors v0.9.1
github.com/spongeprojects/magicconch v0.0.6
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
gopkg.in/yaml.v3 v3.0.1
)
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
9 changes: 5 additions & 4 deletions kube.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package main

import (
"github.com/pkg/errors"
"io/ioutil"
"path"
"path/filepath"
"regexp"

"github.com/pkg/errors"
)

type Candidate struct {
Expand All @@ -31,7 +32,7 @@ func ListKubeconfigCandidatesInDir(dir string) ([]Candidate, error) {
if file.Name() == "config" {
files = append(files, Candidate{
Name: file.Name(),
FullPath: path.Join(dir, file.Name()),
FullPath: filepath.Join(dir, file.Name()),
})
continue
}
Expand All @@ -40,7 +41,7 @@ func ListKubeconfigCandidatesInDir(dir string) ([]Candidate, error) {
if len(matches) >= 2 {
files = append(files, Candidate{
Name: matches[1],
FullPath: path.Join(dir, file.Name()),
FullPath: filepath.Join(dir, file.Name()),
})
}
}
Expand Down
21 changes: 11 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package main
import (
"flag"
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/spongeprojects/magicconch"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"

tea "github.com/charmbracelet/bubbletea"
"github.com/spongeprojects/magicconch"
)

const (
Expand Down Expand Up @@ -39,10 +40,10 @@ var initialModel = &model{}

var (
homeDir = HomeDir()
kubeDir = path.Join(homeDir, ".kube")
defaultConfigPath = path.Join(kubeDir, "config")
configPath = path.Join(kubeDir, "config") // same as defaultConfigPath for now, maybe allow user to specify
cfDir = path.Join(kubeDir, "kubectl-cf")
kubeDir = filepath.Join(homeDir, ".kube")
defaultConfigPath = filepath.Join(kubeDir, "config")
configPath = filepath.Join(kubeDir, "config") // same as defaultConfigPath for now, maybe allow user to specify
cfDir = filepath.Join(kubeDir, "kubectl-cf")
)

func (m *model) quit(farewell string) tea.Cmd {
Expand All @@ -55,7 +56,7 @@ func (m *model) quit(farewell string) tea.Cmd {
}

func (m *model) symlinkConfigPathTo(name string) string {
magicconch.Must(os.WriteFile(path.Join(cfDir, PreviousKubeconfigFullPath), []byte(m.currentConfigPath), 0644))
magicconch.Must(os.WriteFile(filepath.Join(cfDir, PreviousKubeconfigFullPath), []byte(m.currentConfigPath), 0644))

err := Symlink(name, configPath)
if err != nil {
Expand Down Expand Up @@ -101,7 +102,7 @@ func (m *model) Init() tea.Cmd {
addDebugMessage("Current using kubeconfig: %s", initialModel.currentConfigPath)

if debug {
f, err := os.Open(path.Join(cfDir, PreviousKubeconfigFullPath))
f, err := os.Open(filepath.Join(cfDir, PreviousKubeconfigFullPath))
if err != nil {
if !os.IsNotExist(err) {
panic(err)
Expand All @@ -116,7 +117,7 @@ func (m *model) Init() tea.Cmd {

if search := flag.Arg(0); search != "" {
if search == "-" {
f, err := os.Open(path.Join(cfDir, PreviousKubeconfigFullPath))
f, err := os.Open(filepath.Join(cfDir, PreviousKubeconfigFullPath))
if err != nil {
if !os.IsNotExist(err) {
panic(err)
Expand Down

0 comments on commit c644205

Please sign in to comment.