Compare commits
5 commits
d4f086ab54
...
03c09e1da6
Author | SHA1 | Date | |
---|---|---|---|
Lilian Jónsdóttir | 03c09e1da6 | ||
Lilian Jónsdóttir | 40521eb646 | ||
Lilian Jónsdóttir | dd6d3421b0 | ||
Lilian Jónsdóttir | 98a5044662 | ||
Lilian Jónsdóttir | 747a24ebd6 |
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
||||||
bin/
|
bin/
|
||||||
dist/*.tar.gz
|
dist/
|
||||||
|
|
|
@ -48,7 +48,7 @@ Find files in the trash based on the filter flags and any filename args.
|
||||||
#### flags
|
#### flags
|
||||||
|
|
||||||
*--all*, *-a*
|
*--all*, *-a*
|
||||||
operate on all files in trash
|
restore all files in trash
|
||||||
|
|
||||||
*--original-path* dir, *-O* dir
|
*--original-path* dir, *-O* dir
|
||||||
restore files trashed from this directory
|
restore files trashed from this directory
|
||||||
|
@ -60,7 +60,7 @@ Find files in the trash based on the filter flags and any filename args.
|
||||||
#### flags
|
#### flags
|
||||||
|
|
||||||
*--all*, *-a*
|
*--all*, *-a*
|
||||||
operate on all files in trash
|
clean all files in trash
|
||||||
|
|
||||||
*--original-path* dir, *-O* dir
|
*--original-path* dir, *-O* dir
|
||||||
remove files trashed from this directory
|
remove files trashed from this directory
|
||||||
|
@ -117,6 +117,6 @@ See also gt(1) or `gt --help`.
|
||||||
|
|
||||||
## Screenshots
|
## Screenshots
|
||||||
|
|
||||||
![trashing screenshot](./dist/Screenshot01.png)
|
![trashing screenshot](./screenshots/Screenshot01.png)
|
||||||
|
|
||||||
![list screenshot](./dist/Screenshot02.png)
|
![list screenshot](./screenshots/Screenshot02.png)
|
||||||
|
|
8
gt.1
8
gt.1
|
@ -5,11 +5,11 @@
|
||||||
.nh
|
.nh
|
||||||
.ad l
|
.ad l
|
||||||
.\" Begin generated content:
|
.\" Begin generated content:
|
||||||
.TH "gt" "1" "2024-07-31" "gt version v0.0.1" "User Commands"
|
.TH "gt" "1" "2024-07-31" "gt version v0.0.2" "User Commands"
|
||||||
.PP
|
.PP
|
||||||
.SH NAME
|
.SH NAME
|
||||||
.PP
|
.PP
|
||||||
gt - manual page for gt version 0.\&0.\&1
|
gt - manual page for gt version 0.\&0.\&2
|
||||||
.PP
|
.PP
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
.PP
|
.PP
|
||||||
|
@ -27,7 +27,7 @@ g(o)t(rash) is a simple, command line program to interface with the XDG Trash.\&
|
||||||
.PP
|
.PP
|
||||||
.SS VERSION:
|
.SS VERSION:
|
||||||
.PP
|
.PP
|
||||||
0.\&0.\&1
|
0.\&0.\&2
|
||||||
.PP
|
.PP
|
||||||
.SS AUTHOR:
|
.SS AUTHOR:
|
||||||
.PP
|
.PP
|
||||||
|
@ -68,7 +68,7 @@ operate on files recursively
|
||||||
.RE
|
.RE
|
||||||
\fB--work-dir\fR dir, \fB-w\fR dir
|
\fB--work-dir\fR dir, \fB-w\fR dir
|
||||||
.RS 4
|
.RS 4
|
||||||
operate on files in this `DIRECTORY`
|
operate on files in this directory
|
||||||
.PP
|
.PP
|
||||||
.RE
|
.RE
|
||||||
\fB--hidden\fR, \fB-h\fR
|
\fB--hidden\fR, \fB-h\fR
|
||||||
|
|
6
gt.1.scd
6
gt.1.scd
|
@ -1,8 +1,8 @@
|
||||||
gt(1) ["gt version v0.0.1" ["User Commands"]]
|
gt(1) ["gt version v0.0.2" ["User Commands"]]
|
||||||
|
|
||||||
# NAME
|
# NAME
|
||||||
|
|
||||||
gt \- manual page for gt version 0.0.1
|
gt \- manual page for gt version 0.0.2
|
||||||
|
|
||||||
# DESCRIPTION
|
# DESCRIPTION
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ g(o)t(rash) is a simple, command line program to interface with the XDG Trash. F
|
||||||
|
|
||||||
## VERSION:
|
## VERSION:
|
||||||
|
|
||||||
0.0.1
|
0.0.2
|
||||||
|
|
||||||
## AUTHOR:
|
## AUTHOR:
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
const sep = string(os.PathSeparator)
|
const sep = string(os.PathSeparator)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
home string = os.Getenv("HOME")
|
home = os.Getenv("HOME")
|
||||||
pwd, _ = os.Getwd()
|
pwd, _ = os.Getwd()
|
||||||
)
|
)
|
||||||
|
|
||||||
// UnExpand returns dir after expanding some directory shortcuts
|
// UnExpand returns dir after expanding some directory shortcuts
|
||||||
|
|
|
@ -27,9 +27,8 @@ func SortByModified(a, b File) int {
|
||||||
return 1
|
return 1
|
||||||
} else if a.Date().After(b.Date()) {
|
} else if a.Date().After(b.Date()) {
|
||||||
return -1
|
return -1
|
||||||
} else {
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func SortByModifiedReverse(a, b File) int {
|
func SortByModifiedReverse(a, b File) int {
|
||||||
|
@ -37,9 +36,8 @@ func SortByModifiedReverse(a, b File) int {
|
||||||
return 1
|
return 1
|
||||||
} else if a.Date().Before(b.Date()) {
|
} else if a.Date().Before(b.Date()) {
|
||||||
return -1
|
return -1
|
||||||
} else {
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func SortBySize(a, b File) int {
|
func SortBySize(a, b File) int {
|
||||||
|
@ -87,9 +85,8 @@ func SortDirectoriesFirst(a, b File) int {
|
||||||
return 1
|
return 1
|
||||||
} else if a.IsDir() && !b.IsDir() {
|
} else if a.IsDir() && !b.IsDir() {
|
||||||
return -1
|
return -1
|
||||||
} else {
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func SortDirectoriesLast(a, b File) int {
|
func SortDirectoriesLast(a, b File) int {
|
||||||
|
@ -97,9 +94,8 @@ func SortDirectoriesLast(a, b File) int {
|
||||||
return 1
|
return 1
|
||||||
} else if !a.IsDir() && b.IsDir() {
|
} else if !a.IsDir() && b.IsDir() {
|
||||||
return -1
|
return -1
|
||||||
} else {
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func doNameSort(a, b File) int {
|
func doNameSort(a, b File) int {
|
||||||
|
@ -119,7 +115,6 @@ func doNameSort(a, b File) int {
|
||||||
func getSortingSize(f File) int64 {
|
func getSortingSize(f File) int64 {
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
return -1
|
return -1
|
||||||
} else {
|
|
||||||
return f.Filesize()
|
|
||||||
}
|
}
|
||||||
|
return f.Filesize()
|
||||||
}
|
}
|
||||||
|
|
|
@ -296,19 +296,19 @@ func ensureUniqueName(filename, trashDir string) (string, string) {
|
||||||
// doesn't exist, so use it
|
// doesn't exist, so use it
|
||||||
path := filepath.Join(filedir, filename)
|
path := filepath.Join(filedir, filename)
|
||||||
return info, path
|
return info, path
|
||||||
} else {
|
}
|
||||||
// otherwise, try random suffixes until one works
|
|
||||||
log.Debugf("%s exists in trash, generating random name", filename)
|
// otherwise, try random suffixes until one works
|
||||||
var tries int
|
log.Debugf("%s exists in trash, generating random name", filename)
|
||||||
for {
|
var tries int
|
||||||
tries++
|
for {
|
||||||
rando := randomFilename(randomStrLength)
|
tries++
|
||||||
newName := filepath.Join(infodir, filename+rando+trashInfoExt)
|
rando := randomFilename(randomStrLength)
|
||||||
if _, err := os.Stat(newName); os.IsNotExist(err) {
|
newName := filepath.Join(infodir, filename+rando+trashInfoExt)
|
||||||
path := filepath.Join(filedir, filename+rando)
|
if _, err := os.Stat(newName); os.IsNotExist(err) {
|
||||||
log.Debugf("settled on random name %s%s on the %s try", filename, rando, humanize.Ordinal(tries))
|
path := filepath.Join(filedir, filename+rando)
|
||||||
return newName, path
|
log.Debugf("settled on random name %s%s on the %s try", filename, rando, humanize.Ordinal(tries))
|
||||||
}
|
return newName, path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ package interactive
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -12,6 +13,7 @@ import (
|
||||||
"git.burning.moe/celediel/gt/internal/files"
|
"git.burning.moe/celediel/gt/internal/files"
|
||||||
"git.burning.moe/celediel/gt/internal/interactive/modes"
|
"git.burning.moe/celediel/gt/internal/interactive/modes"
|
||||||
"git.burning.moe/celediel/gt/internal/interactive/sorting"
|
"git.burning.moe/celediel/gt/internal/interactive/sorting"
|
||||||
|
"golang.org/x/term"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/key"
|
"github.com/charmbracelet/bubbles/key"
|
||||||
"github.com/charmbracelet/bubbles/table"
|
"github.com/charmbracelet/bubbles/table"
|
||||||
|
@ -84,64 +86,37 @@ type model struct {
|
||||||
fltrfiles files.Files
|
fltrfiles files.Files
|
||||||
}
|
}
|
||||||
|
|
||||||
func newModel(fls []files.File, width, height int, selectall, readonly, once bool, workdir string, mode modes.Mode) model {
|
func newModel(fls []files.File, selectall, readonly, once bool, workdir string, mode modes.Mode) (m model) {
|
||||||
var (
|
m = model{
|
||||||
fwidth = int(math.Round(float64(width-woffset) * filenameColumnW))
|
keys: defaultKeyMap(),
|
||||||
owidth = int(math.Round(float64(width-woffset) * pathColumnW))
|
readonly: readonly,
|
||||||
dwidth = int(math.Round(float64(width-woffset) * dateColumnW))
|
once: once,
|
||||||
swidth = int(math.Round(float64(width-woffset) * sizeColumnW))
|
mode: mode,
|
||||||
cwidth = int(math.Round(float64(width-woffset) * checkColumnW))
|
selected: map[string]bool{},
|
||||||
theight = min(height-hoffset, len(fls))
|
selectsize: 0,
|
||||||
|
files: fls,
|
||||||
|
}
|
||||||
|
|
||||||
mdl = model{
|
m.termwidth, m.termheight = termSizes()
|
||||||
keys: defaultKeyMap(),
|
|
||||||
readonly: readonly,
|
|
||||||
once: once,
|
|
||||||
termheight: height,
|
|
||||||
termwidth: width,
|
|
||||||
mode: mode,
|
|
||||||
selected: map[string]bool{},
|
|
||||||
selectsize: 0,
|
|
||||||
files: fls,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
if workdir != "" {
|
if workdir != "" {
|
||||||
mdl.workdir = filepath.Clean(workdir)
|
m.workdir = filepath.Clean(workdir)
|
||||||
}
|
}
|
||||||
|
|
||||||
rows := mdl.freshRows()
|
rows := m.freshRows()
|
||||||
|
columns := m.freshColumns()
|
||||||
|
|
||||||
var datecolumn string
|
theight := min(m.termheight-hoffset, len(fls))
|
||||||
switch mdl.mode {
|
m.table = createTable(columns, rows, theight)
|
||||||
case modes.Trashing:
|
|
||||||
datecolumn = modifiedColumn
|
|
||||||
default:
|
|
||||||
datecolumn = trashedColumn
|
|
||||||
}
|
|
||||||
|
|
||||||
columns := []table.Column{
|
m.sorting = sorting.Name
|
||||||
{Title: filenameColumn, Width: fwidth},
|
m.sort()
|
||||||
{Title: pathColumn, Width: owidth},
|
|
||||||
{Title: datecolumn, Width: dwidth},
|
|
||||||
{Title: sizeColumn, Width: swidth},
|
|
||||||
}
|
|
||||||
if !mdl.readonly {
|
|
||||||
columns = append(columns, table.Column{Title: uncheck, Width: cwidth})
|
|
||||||
} else {
|
|
||||||
columns[0].Width += cwidth
|
|
||||||
}
|
|
||||||
|
|
||||||
mdl.table = createTable(columns, rows, theight)
|
|
||||||
|
|
||||||
mdl.sorting = sorting.Name
|
|
||||||
mdl.sort()
|
|
||||||
|
|
||||||
if selectall {
|
if selectall {
|
||||||
mdl.selectAll()
|
m.selectAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
return mdl
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type keyMap struct {
|
type keyMap struct {
|
||||||
|
@ -239,6 +214,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
|
case tea.WindowSizeMsg:
|
||||||
|
m.updateTableSize()
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
if m.filtering {
|
if m.filtering {
|
||||||
switch {
|
switch {
|
||||||
|
@ -312,7 +289,6 @@ func (m model) View() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m model) showHelp() string {
|
func (m model) showHelp() string {
|
||||||
// TODO: maybe use bubbletea built in help
|
|
||||||
var filterText string
|
var filterText string
|
||||||
if m.filter != "" {
|
if m.filter != "" {
|
||||||
filterText = fmt.Sprintf(" (%s)", m.filter)
|
filterText = fmt.Sprintf(" (%s)", m.filter)
|
||||||
|
@ -613,6 +589,48 @@ func (m *model) filteredFiles() (filteredFiles files.Files) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *model) freshColumns() []table.Column {
|
||||||
|
var (
|
||||||
|
fwidth = int(math.Round(float64(m.termwidth-woffset) * filenameColumnW))
|
||||||
|
owidth = int(math.Round(float64(m.termwidth-woffset) * pathColumnW))
|
||||||
|
dwidth = int(math.Round(float64(m.termwidth-woffset) * dateColumnW))
|
||||||
|
swidth = int(math.Round(float64(m.termwidth-woffset) * sizeColumnW))
|
||||||
|
cwidth = int(math.Round(float64(m.termwidth-woffset) * checkColumnW))
|
||||||
|
datecolumn string
|
||||||
|
)
|
||||||
|
|
||||||
|
switch m.mode {
|
||||||
|
case modes.Trashing:
|
||||||
|
datecolumn = modifiedColumn
|
||||||
|
default:
|
||||||
|
datecolumn = trashedColumn
|
||||||
|
}
|
||||||
|
|
||||||
|
columns := []table.Column{
|
||||||
|
{Title: filenameColumn, Width: fwidth},
|
||||||
|
{Title: pathColumn, Width: owidth},
|
||||||
|
{Title: datecolumn, Width: dwidth},
|
||||||
|
{Title: sizeColumn, Width: swidth},
|
||||||
|
}
|
||||||
|
|
||||||
|
if !m.readonly {
|
||||||
|
columns = append(columns, table.Column{Title: uncheck, Width: cwidth})
|
||||||
|
} else {
|
||||||
|
columns[0].Width += cwidth
|
||||||
|
}
|
||||||
|
|
||||||
|
return columns
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *model) updateTableSize() {
|
||||||
|
width, height := termSizes()
|
||||||
|
m.termheight = height
|
||||||
|
m.termwidth = width - poffset
|
||||||
|
m.table.SetWidth(m.termwidth)
|
||||||
|
m.updateTableHeight()
|
||||||
|
m.table.SetColumns(m.freshColumns())
|
||||||
|
}
|
||||||
|
|
||||||
func (m *model) updateTableHeight() {
|
func (m *model) updateTableHeight() {
|
||||||
h := min(m.termheight-hoffset, len(m.table.Rows()))
|
h := min(m.termheight-hoffset, len(m.table.Rows()))
|
||||||
m.table.SetHeight(h)
|
m.table.SetHeight(h)
|
||||||
|
@ -621,8 +639,8 @@ func (m *model) updateTableHeight() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Select(fls files.Files, width, height int, selectall, once bool, workdir string, mode modes.Mode) (files.Files, modes.Mode, error) {
|
func Select(fls files.Files, selectall, once bool, workdir string, mode modes.Mode) (files.Files, modes.Mode, error) {
|
||||||
mdl := newModel(fls, width, height, selectall, false, once, workdir, mode)
|
mdl := newModel(fls, selectall, false, once, workdir, mode)
|
||||||
endmodel, err := tea.NewProgram(mdl).Run()
|
endmodel, err := tea.NewProgram(mdl).Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fls, 0, err
|
return fls, 0, err
|
||||||
|
@ -634,8 +652,8 @@ func Select(fls files.Files, width, height int, selectall, once bool, workdir st
|
||||||
return m.selectedFiles(), m.mode, nil
|
return m.selectedFiles(), m.mode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Show(fls files.Files, width, height int, once bool, workdir string) error {
|
func Show(fls files.Files, once bool, workdir string) error {
|
||||||
mdl := newModel(fls, width, height, false, true, once, workdir, modes.Listing)
|
mdl := newModel(fls, false, true, once, workdir, modes.Listing)
|
||||||
if _, err := tea.NewProgram(mdl).Run(); err != nil {
|
if _, err := tea.NewProgram(mdl).Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -725,3 +743,14 @@ func isMatch(pattern, filename string) bool {
|
||||||
f := strings.ToLower(filename)
|
f := strings.ToLower(filename)
|
||||||
return fuzzy.Match(p, f)
|
return fuzzy.Match(p, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func termSizes() (width int, height int) {
|
||||||
|
// read the term height and width for tables
|
||||||
|
var err error
|
||||||
|
width, height, err = term.GetSize(int(os.Stdout.Fd()))
|
||||||
|
if err != nil {
|
||||||
|
width = 80
|
||||||
|
height = 24
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -11,8 +11,6 @@ import (
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: use charm stuff for this
|
|
||||||
|
|
||||||
func YesNo(prompt string) bool {
|
func YesNo(prompt string) bool {
|
||||||
return AskRune(prompt, "y/n") == 'y'
|
return AskRune(prompt, "y/n") == 'y'
|
||||||
}
|
}
|
||||||
|
|
33
justfile
33
justfile
|
@ -1,10 +1,16 @@
|
||||||
binary := "gt"
|
binary := "gt"
|
||||||
version := "0.0.1"
|
version := "0.0.2"
|
||||||
build_dir := "bin"
|
build_dir := "bin"
|
||||||
dist_dir := "dist"
|
dist_dir := "dist"
|
||||||
cmd := "."
|
cmd := "."
|
||||||
output := "." / build_dir / binary
|
output := "." / build_dir / binary
|
||||||
dist := "." / dist_dir / binary
|
dist := "." / dist_dir / binary
|
||||||
|
contrib_dir := "." / "contrib"
|
||||||
|
screenshots_dir := "screenshots"
|
||||||
|
archive_base := dist_dir / binary + "-" + version
|
||||||
|
linux_archive := archive_base + "-x86_64.tar"
|
||||||
|
arm64_archive := archive_base + "-arm64.tar"
|
||||||
|
arm_archive := archive_base + "-arm.tar"
|
||||||
|
|
||||||
# do the thing
|
# do the thing
|
||||||
default: test check install
|
default: test check install
|
||||||
|
@ -13,12 +19,24 @@ default: test check install
|
||||||
build:
|
build:
|
||||||
go build -o {{output}} {{cmd}}
|
go build -o {{output}} {{cmd}}
|
||||||
|
|
||||||
package:
|
package $CGO_ENABLED="0": man
|
||||||
go build -o {{binary}}
|
go build -o {{binary}} {{cmd}}
|
||||||
distrobox enter alpine -- go build -o {{binary}}-musl {{cmd}}
|
tar cafv {{linux_archive}} {{binary}} {{binary}}.1 README.md LICENSE {{screenshots_dir}}
|
||||||
tar cafv {{dist_dir}}/{{binary}}-{{version}}-x86_64.tar.gz {{binary}} README.md LICENSE
|
tar rafv {{linux_archive}} -C {{contrib_dir}} "completions"
|
||||||
tar cafv {{dist_dir}}/{{binary}}-{{version}}-x86_64-musl.tar.gz {{binary}}-musl README.md LICENSE
|
gzip -f {{linux_archive}}
|
||||||
rm {{binary}} {{binary}}-musl
|
rm {{binary}}
|
||||||
|
|
||||||
|
GOARCH="arm" GOARM="7" go build -o {{binary}} {{cmd}}
|
||||||
|
tar cafv {{arm_archive}} {{binary}} {{binary}}.1 README.md LICENSE {{screenshots_dir}}
|
||||||
|
tar rafv {{arm_archive}} -C {{contrib_dir}} "completions"
|
||||||
|
gzip -f {{arm_archive}}
|
||||||
|
rm {{binary}}
|
||||||
|
|
||||||
|
GOARCH="arm64" go build -o {{binary}} {{cmd}}
|
||||||
|
tar cafv {{arm64_archive}} {{binary}} {{binary}}.1 README.md LICENSE {{screenshots_dir}}
|
||||||
|
tar rafv {{arm64_archive}} -C {{contrib_dir}} "completions"
|
||||||
|
gzip -f {{arm64_archive}}
|
||||||
|
rm {{binary}}
|
||||||
|
|
||||||
# run from source
|
# run from source
|
||||||
run:
|
run:
|
||||||
|
@ -44,7 +62,6 @@ install-man:
|
||||||
# clean up after yourself
|
# clean up after yourself
|
||||||
clean:
|
clean:
|
||||||
-rm {{output}}
|
-rm {{output}}
|
||||||
-rm {{output}}-musl
|
|
||||||
-rm {{dist_dir}}/*.tar.gz
|
-rm {{dist_dir}}/*.tar.gz
|
||||||
|
|
||||||
# run go tests
|
# run go tests
|
||||||
|
|
25
main.go
25
main.go
|
@ -1,3 +1,4 @@
|
||||||
|
// Package main does the thing
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -17,13 +18,12 @@ import (
|
||||||
"github.com/adrg/xdg"
|
"github.com/adrg/xdg"
|
||||||
"github.com/charmbracelet/log"
|
"github.com/charmbracelet/log"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"golang.org/x/term"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
appname string = "gt"
|
appname string = "gt"
|
||||||
appsubtitle string = "xdg trash cli"
|
appsubtitle string = "xdg trash cli"
|
||||||
appversion string = "v0.0.1"
|
appversion string = "v0.0.2"
|
||||||
appdesc string = `A small command line program to interface with the
|
appdesc string = `A small command line program to interface with the
|
||||||
Freedesktop.org / XDG trash specification.
|
Freedesktop.org / XDG trash specification.
|
||||||
|
|
||||||
|
@ -45,8 +45,6 @@ var (
|
||||||
askconfirm, all bool
|
askconfirm, all bool
|
||||||
workdir, ogdir cli.Path
|
workdir, ogdir cli.Path
|
||||||
recursive bool
|
recursive bool
|
||||||
termwidth int
|
|
||||||
termheight int
|
|
||||||
|
|
||||||
trashDir = filepath.Join(xdg.DataHome, "Trash")
|
trashDir = filepath.Join(xdg.DataHome, "Trash")
|
||||||
|
|
||||||
|
@ -64,15 +62,6 @@ var (
|
||||||
log.Errorf("unknown log level '%s' (possible values: debug, info, warn, error, fatal, default: warn)", loglvl)
|
log.Errorf("unknown log level '%s' (possible values: debug, info, warn, error, fatal, default: warn)", loglvl)
|
||||||
}
|
}
|
||||||
|
|
||||||
// read the term height and width for tables
|
|
||||||
width, height, e := term.GetSize(int(os.Stdout.Fd()))
|
|
||||||
if e != nil {
|
|
||||||
width = 80
|
|
||||||
height = 24
|
|
||||||
}
|
|
||||||
termwidth = width
|
|
||||||
termheight = height
|
|
||||||
|
|
||||||
// ensure trash directories exist
|
// ensure trash directories exist
|
||||||
if _, e := os.Stat(trashDir); os.IsNotExist(e) {
|
if _, e := os.Stat(trashDir); os.IsNotExist(e) {
|
||||||
if err := os.Mkdir(trashDir, executePerm); err != nil {
|
if err := os.Mkdir(trashDir, executePerm); err != nil {
|
||||||
|
@ -132,7 +121,7 @@ var (
|
||||||
fmt.Fprintln(os.Stdout, msg)
|
fmt.Fprintln(os.Stdout, msg)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
selected, mode, err = interactive.Select(infiles, termwidth, termheight, false, false, workdir, modes.Interactive)
|
selected, mode, err = interactive.Select(infiles, false, false, workdir, modes.Interactive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -233,7 +222,7 @@ var (
|
||||||
filesToTrash = append(filesToTrash, fls...)
|
filesToTrash = append(filesToTrash, fls...)
|
||||||
}
|
}
|
||||||
|
|
||||||
selected, _, err := interactive.Select(filesToTrash, termwidth, termheight, false, false, workdir, modes.Trashing)
|
selected, _, err := interactive.Select(filesToTrash, false, false, workdir, modes.Trashing)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -272,7 +261,7 @@ var (
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return interactive.Show(fls, termwidth, termheight, noInterArg, workdir)
|
return interactive.Show(fls, noInterArg, workdir)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,7 +283,7 @@ var (
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
selected, _, err := interactive.Select(fls, termwidth, termheight, all, all, workdir, modes.Restoring)
|
selected, _, err := interactive.Select(fls, all, all, workdir, modes.Restoring)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -323,7 +312,7 @@ var (
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
selected, _, err := interactive.Select(fls, termwidth, termheight, all, all, workdir, modes.Cleaning)
|
selected, _, err := interactive.Select(fls, all, all, workdir, modes.Cleaning)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
Before Width: | Height: | Size: 324 KiB After Width: | Height: | Size: 324 KiB |
Loading…
Reference in a new issue