summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pedersen <Limero@users.noreply.github.com>2024-11-04 20:08:28 +0700
committerGitHub <noreply@github.com>2024-11-05 00:08:28 +1100
commit0b519870441671bda90be725ff64748d836c0684 (patch)
tree2fffcdb6e0afc85e94e565057b694282e1334661
parentd9a6ca5766c5cc6692f5e1046e7ad551c109ceea (diff)
Use new slices/cmp standard lib (#1834)
-rw-r--r--eval.go20
-rw-r--r--os.go35
-rw-r--r--os_windows.go11
3 files changed, 25 insertions, 41 deletions
diff --git a/eval.go b/eval.go
index 7fc05cc..a4631ea 100644
--- a/eval.go
+++ b/eval.go
@@ -7,6 +7,7 @@ import (
"log"
"os"
"path/filepath"
+ "slices"
"strconv"
"strings"
"time"
@@ -2111,8 +2112,7 @@ func (e *callExpr) eval(app *app, args []string) {
}
ind := locs[len(locs)-1][3]
old := app.ui.cmdAccRight
- app.ui.cmdAccRight = append([]rune{}, []rune(string(app.ui.cmdAccLeft)[ind:])...)
- app.ui.cmdAccRight = append(app.ui.cmdAccRight, old...)
+ app.ui.cmdAccRight = append([]rune(string(app.ui.cmdAccLeft)[ind:]), old...)
app.ui.cmdAccLeft = []rune(string(app.ui.cmdAccLeft)[:ind])
case "cmd-capitalize-word":
if len(app.ui.cmdAccRight) == 0 {
@@ -2205,15 +2205,13 @@ func (e *callExpr) eval(app *app, args []string) {
beg1, end1 := locs[len(locs)-2][0], locs[len(locs)-2][1]
beg2, end2 := locs[len(locs)-1][0], locs[len(locs)-1][1]
- var acc []rune
-
- acc = append(acc, []rune(string(app.ui.cmdAccLeft)[:beg1])...)
- acc = append(acc, []rune(string(app.ui.cmdAccLeft)[beg2:end2])...)
- acc = append(acc, []rune(string(app.ui.cmdAccLeft)[end1:beg2])...)
- acc = append(acc, []rune(string(app.ui.cmdAccLeft)[beg1:end1])...)
- acc = append(acc, []rune(string(app.ui.cmdAccLeft)[end2:])...)
-
- app.ui.cmdAccLeft = acc
+ app.ui.cmdAccLeft = slices.Concat(
+ []rune(string(app.ui.cmdAccLeft)[:beg1]),
+ []rune(string(app.ui.cmdAccLeft)[beg2:end2]),
+ []rune(string(app.ui.cmdAccLeft)[end1:beg2]),
+ []rune(string(app.ui.cmdAccLeft)[beg1:end1]),
+ []rune(string(app.ui.cmdAccLeft)[end2:]),
+ )
update(app)
default:
cmd, ok := gOpts.cmds[e.name]
diff --git a/os.go b/os.go
index 88155bb..ff3669e 100644
--- a/os.go
+++ b/os.go
@@ -3,6 +3,7 @@
package main
import (
+ "cmp"
"fmt"
"log"
"os"
@@ -53,10 +54,7 @@ func init() {
}
if envEditor == "" {
- envEditor = os.Getenv("EDITOR")
- if envEditor == "" {
- envEditor = "vi"
- }
+ envEditor = cmp.Or(os.Getenv("EDITOR"), "vi")
}
if envPager == "" {
@@ -86,13 +84,11 @@ func init() {
}
gUser = u
- config := os.Getenv("LF_CONFIG_HOME")
- if config == "" {
- config = os.Getenv("XDG_CONFIG_HOME")
- }
- if config == "" {
- config = filepath.Join(gUser.HomeDir, ".config")
- }
+ config := cmp.Or(
+ os.Getenv("LF_CONFIG_HOME"),
+ os.Getenv("XDG_CONFIG_HOME"),
+ filepath.Join(gUser.HomeDir, ".config"),
+ )
gConfigPaths = []string{
filepath.Join("/etc", "lf", "lfrc"),
@@ -109,23 +105,18 @@ func init() {
filepath.Join(config, "lf", "icons"),
}
- data := os.Getenv("LF_DATA_HOME")
- if data == "" {
- data = os.Getenv("XDG_DATA_HOME")
- }
- if data == "" {
- data = filepath.Join(gUser.HomeDir, ".local", "share")
- }
+ data := cmp.Or(
+ os.Getenv("LF_DATA_HOME"),
+ os.Getenv("XDG_DATA_HOME"),
+ filepath.Join(gUser.HomeDir, ".local", "share"),
+ )
gFilesPath = filepath.Join(data, "lf", "files")
gMarksPath = filepath.Join(data, "lf", "marks")
gTagsPath = filepath.Join(data, "lf", "tags")
gHistoryPath = filepath.Join(data, "lf", "history")
- runtime := os.Getenv("XDG_RUNTIME_DIR")
- if runtime == "" {
- runtime = os.TempDir()
- }
+ runtime := cmp.Or(os.Getenv("XDG_RUNTIME_DIR"), os.TempDir())
gDefaultSocketPath = filepath.Join(runtime, fmt.Sprintf("lf.%s.sock", gUser.Username))
}
diff --git a/os_windows.go b/os_windows.go
index 84dc187..dac8f44 100644
--- a/os_windows.go
+++ b/os_windows.go
@@ -1,6 +1,7 @@
package main
import (
+ "cmp"
"fmt"
"log"
"os"
@@ -47,10 +48,7 @@ func init() {
}
if envEditor == "" {
- envEditor = os.Getenv("EDITOR")
- if envEditor == "" {
- envEditor = "notepad"
- }
+ envEditor = cmp.Or(os.Getenv("EDITOR"), "notepad")
}
if envPager == "" {
@@ -76,10 +74,7 @@ func init() {
Username: username,
}
- data := os.Getenv("LF_CONFIG_HOME")
- if data == "" {
- data = os.Getenv("LOCALAPPDATA")
- }
+ data := cmp.Or(os.Getenv("LF_CONFIG_HOME"), os.Getenv("LOCALAPPDATA"))
gConfigPaths = []string{
filepath.Join(os.Getenv("ProgramData"), "lf", "lfrc"),