Merge remote-tracking branch 'refs/remotes/origin/main'

This commit is contained in:
2025-12-11 14:48:48 +01:00
2 changed files with 166 additions and 64 deletions
+32
View File
@@ -8,6 +8,10 @@
"command": "df -h /path/to/mount", "command": "df -h /path/to/mount",
"desc": "Show statistics about a drive (remove path for all)" "desc": "Show statistics about a drive (remove path for all)"
}, },
{
"command": "free -h",
"desc": "Display memory usage in human-readable units"
},
{ {
"command": "find /path/to/directory -type f | wc -l", "command": "find /path/to/directory -type f | wc -l",
"desc": "Show amount of files in directory and its sub-directories" "desc": "Show amount of files in directory and its sub-directories"
@@ -23,6 +27,10 @@
{ {
"command": "echo Hostname: $(hostname); echo Local_IP: $(hostname -i | awk '{print $1}'); echo Default_Gateway: $(ip route | awk '/default/ {print $3}')", "command": "echo Hostname: $(hostname); echo Local_IP: $(hostname -i | awk '{print $1}'); echo Default_Gateway: $(ip route | awk '/default/ {print $3}')",
"desc": "Print IP Address, Hostname, Default Route" "desc": "Print IP Address, Hostname, Default Route"
},
{
"command": "tar -czf backup.tgz /path/to/dir",
"desc": "Create a quick compressed backup of a directory"
} }
{ {
"command": "find . -type f -iname 'myfile.txt'", "command": "find . -type f -iname 'myfile.txt'",
@@ -38,6 +46,18 @@
"command": "python3 -m venv .venv && source .venv/bin/activate", "command": "python3 -m venv .venv && source .venv/bin/activate",
"desc": "Initialise a (simple) .venv and activate it" "desc": "Initialise a (simple) .venv and activate it"
}, },
{
"command": "python -m http.server 8000",
"desc": "Serve the current directory over HTTP on port 8000"
},
{
"command": "python -m pip install --upgrade pip",
"desc": "Upgrade pip to the latest version"
},
{
"command": "python -m pip freeze > requirements.txt",
"desc": "Export current Python dependencies to requirements.txt"
},
{ {
"command": "pip install jupyterlab ipykernel && python3 -m ipykernel install --user --name=project-name", "command": "pip install jupyterlab ipykernel && python3 -m ipykernel install --user --name=project-name",
"desc": "Install and initialise the kernel to use in jupyter" "desc": "Install and initialise the kernel to use in jupyter"
@@ -52,6 +72,18 @@
"command": "go mod init github.com/username/projectname", "command": "go mod init github.com/username/projectname",
"desc": "Initialise a go project and create a mod file" "desc": "Initialise a go project and create a mod file"
}, },
{
"command": "go test ./...",
"desc": "Run all Go tests recursively"
},
{
"command": "go test -bench=. ./...",
"desc": "Run all benchmarks in the module"
},
{
"command": "go list -m all",
"desc": "List all resolved module dependencies"
},
{ {
"command": "go get github.com/some/package@latest", "command": "go get github.com/some/package@latest",
"desc": "Add dependencies" "desc": "Add dependencies"
+88 -18
View File
@@ -6,18 +6,17 @@ import (
//"sort" //"sort"
//"strings" //"strings"
"github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list" "github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss" "github.com/charmbracelet/lipgloss"
) )
type item struct { type item struct {
title string title string
description string description string
} }
func (i item) Title() string { return i.title } func (i item) Title() string { return i.title }
func (i item) Description() string { return i.description } func (i item) Description() string { return i.description }
func (i item) FilterValue() string { return i.title } func (i item) FilterValue() string { return i.title }
@@ -30,7 +29,9 @@ type model struct {
currentView view currentView view
currentKey string currentKey string
selectedCmd string selectedCmd string
categoryIndex int
} }
func (m model) Init() tea.Cmd { return nil } func (m model) Init() tea.Cmd { return nil }
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
@@ -48,10 +49,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
selected, ok := m.list.SelectedItem().(item) selected, ok := m.list.SelectedItem().(item)
if ok { if ok {
if m.currentView == viewCategories { if m.currentView == viewCategories {
m.categoryIndex = m.list.Index()
m.currentKey = selected.title m.currentKey = selected.title
m.currentView = viewCommands m.currentView = viewCommands
m.list.Title = m.currentKey m.list.Title = m.currentKey
m.list.SetItems(cmdItemsToList(m.commands.Get(m.currentKey))) m.list.SetItems(cmdItemsToList(m.commands.Get(m.currentKey)))
m.list.Select(0)
} else if m.currentView == viewCommands { } else if m.currentView == viewCommands {
m.selectedCmd = selected.title m.selectedCmd = selected.title
return m, tea.Quit return m, tea.Quit
@@ -64,6 +67,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.currentView = viewCategories m.currentView = viewCategories
m.list.Title = "Choose a list of commands" m.list.Title = "Choose a list of commands"
m.list.SetItems(cmdListKeysToList(m.commands)) m.list.SetItems(cmdListKeysToList(m.commands))
m.list.Select(m.categoryIndex)
} else if m.currentView == viewCategories {
return m, tea.Quit
} }
} }
@@ -84,7 +90,9 @@ func (m model) View() string {
return docStyle.Render(m.list.View()) return docStyle.Render(m.list.View())
} }
var docStyle = lipgloss.NewStyle().Margin(1, 2) var docStyle = lipgloss.NewStyle().
Margin(1, 2).
Background(lipgloss.Color("235"))
const ( const (
viewCategories view = iota viewCategories view = iota
@@ -93,25 +101,12 @@ const (
func StartTui(commands CmdList) { func StartTui(commands CmdList) {
delegate := list.NewDefaultDelegate() delegate := newStyledDelegate()
backKey := key.NewBinding(
key.WithKeys("b"),
key.WithHelp("b", "back"),
)
delegate.ShortHelpFunc = func() []key.Binding{
return []key.Binding{
backKey,
}
}
delegate.FullHelpFunc = func() [][]key.Binding{
return [][]key.Binding{
{backKey},
}
}
items := cmdListKeysToList(commands) items := cmdListKeysToList(commands)
l := list.New(items, delegate, 0, 0) l := list.New(items, delegate, 0, 0)
l.Title = "Choose a list of commands" l.Title = "Choose a list of commands"
l.Styles = newListStyles()
m := model{ m := model{
list: l, list: l,
@@ -156,3 +151,78 @@ func cmdItemsToList(cmds []CmdItem) []list.Item {
} }
return items return items
} }
func newStyledDelegate() list.DefaultDelegate {
delegate := list.NewDefaultDelegate()
backKey := key.NewBinding(
key.WithKeys("b"),
key.WithHelp("b", "back/exit"),
)
delegate.ShortHelpFunc = func() []key.Binding {
return []key.Binding{backKey}
}
delegate.FullHelpFunc = func() [][]key.Binding {
return [][]key.Binding{
{backKey},
}
}
delegate.SetSpacing(0)
styles := list.NewDefaultItemStyles()
styles.NormalTitle = styles.NormalTitle.
Foreground(lipgloss.Color("110")).
PaddingLeft(1)
styles.NormalDesc = styles.NormalDesc.
Foreground(lipgloss.Color("247")).
PaddingLeft(2)
styles.SelectedTitle = lipgloss.NewStyle().
Foreground(lipgloss.Color("0")).
Background(lipgloss.Color("187")).
BorderStyle(lipgloss.RoundedBorder()).
BorderForeground(lipgloss.Color("186")).
Padding(0, 1)
styles.SelectedDesc = styles.SelectedTitle.
Foreground(lipgloss.Color("232")).
Background(lipgloss.Color("230")).
Padding(0, 1)
styles.FilterMatch = styles.FilterMatch.
Foreground(lipgloss.Color("226"))
delegate.Styles = styles
return delegate
}
func newListStyles() list.Styles {
styles := list.DefaultStyles()
styles.Title = lipgloss.NewStyle().
BorderStyle(lipgloss.ThickBorder()).
BorderForeground(lipgloss.Color("180")).
Background(lipgloss.Color("23")).
Foreground(lipgloss.Color("230")).
Padding(0, 2)
styles.TitleBar = styles.TitleBar.MarginBottom(1)
styles.StatusBar = styles.StatusBar.
Background(lipgloss.Color("236")).
Foreground(lipgloss.Color("252")).
Padding(0, 1)
styles.StatusEmpty = styles.StatusEmpty.Foreground(lipgloss.Color("60"))
styles.PaginationStyle = styles.PaginationStyle.
Foreground(lipgloss.Color("244")).
PaddingLeft(4)
styles.HelpStyle = styles.HelpStyle.
MarginLeft(1).
Foreground(lipgloss.Color("244"))
styles.ActivePaginationDot = styles.ActivePaginationDot.
Foreground(lipgloss.Color("220"))
styles.InactivePaginationDot = styles.InactivePaginationDot.
Foreground(lipgloss.Color("238"))
return styles
}