diff --git a/group_vars/all.yml b/group_vars/all.yml index 0c8b53a..f3e3092 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -175,6 +175,33 @@ config_files: - name: "Herdr config" src: "./templates/herdr/config.toml" dest: "~/.config/herdr/config.toml" + - name: "Television cable: channels" + src: "./templates/television/cable/channels.toml" + dest: "~/.config/television/cable/channels.toml" + - name: "Television cable: dirs" + src: "./templates/television/cable/dirs.toml" + dest: "~/.config/television/cable/dirs.toml" + - name: "Television cable: env" + src: "./templates/television/cable/env.toml" + dest: "~/.config/television/cable/env.toml" + - name: "Television cable: files" + src: "./templates/television/cable/files.toml" + dest: "~/.config/television/cable/files.toml" + - name: "Television cable: gh-prs" + src: "./templates/television/cable/gh-prs.toml" + dest: "~/.config/television/cable/gh-prs.toml" + - name: "Television cable: git-log" + src: "./templates/television/cable/git-log.toml" + dest: "~/.config/television/cable/git-log.toml" + - name: "Television cable: path" + src: "./templates/television/cable/path.toml" + dest: "~/.config/television/cable/path.toml" + - name: "Television cable: recent-files" + src: "./templates/television/cable/recent-files.toml" + dest: "~/.config/television/cable/recent-files.toml" + - name: "Television cable: text" + src: "./templates/television/cable/text.toml" + dest: "~/.config/television/cable/text.toml" pi_agent_settings_path: "~/.pi/agent/settings.json" pi_agent_settings_overrides: |- diff --git a/templates/television/cable/channels.toml b/templates/television/cable/channels.toml new file mode 100644 index 0000000..9c8b922 --- /dev/null +++ b/templates/television/cable/channels.toml @@ -0,0 +1,19 @@ +[metadata] +name = "channels" +description = "Select a television channel" +requirements = ["tv", "bat"] + +[source] +command = ["tv list-channels"] + +[preview] +command = "bat -pn --color always ${TELEVISION_CONFIG:-${XDG_CONFIG_HOME:-$HOME/.config}/television}/cable/{}.toml" +shell = "bash" + +[keybindings] +enter = "actions:channel-enter" + +[actions.channel-enter] +description = "Enter a television channel" +command = "tv {}" +mode = "execute" diff --git a/templates/television/cable/dirs.toml b/templates/television/cable/dirs.toml new file mode 100644 index 0000000..4dcc5a7 --- /dev/null +++ b/templates/television/cable/dirs.toml @@ -0,0 +1,26 @@ +[metadata] +name = "dirs" +description = "A channel to select from directories" +requirements = ["fd"] + +[source] +command = [ + { name = "Default", run = "fd -t d" }, + { name = "Hidden", run = "fd -t d --hidden" }, +] + +[preview] +command = "ls -la --color=always '{}'" + +[keybindings] +shortcut = "f2" + +[actions.cd] +description = "Open a shell in the selected directory" +command = "cd {} && $SHELL" +mode = "execute" + +[actions.goto_parent_dir] +description = "Re-opens tv in the parent directory" +command = "tv dirs .." +mode = "execute" diff --git a/templates/television/cable/env.toml b/templates/television/cable/env.toml new file mode 100644 index 0000000..190144b --- /dev/null +++ b/templates/television/cable/env.toml @@ -0,0 +1,22 @@ +[metadata] +name = "env" +description = "A channel to select from environment variables" + +[source] +command = "printenv" +output = "{split:=:1..}" # output the value + +[preview] +command = "echo '{split:=:1..}'" + +[ui] +layout = "portrait" +preview_panel = { size = 20, header = "{split:=:0}" } + +[keybindings] +shortcut = "f3" + +[actions.name] +description = "Output the variable name instead of the value" +command = "echo '{split:=:0}'" +mode = "execute" diff --git a/templates/television/cable/files.toml b/templates/television/cable/files.toml new file mode 100644 index 0000000..166dfcc --- /dev/null +++ b/templates/television/cable/files.toml @@ -0,0 +1,32 @@ +[metadata] +name = "files" +description = "A channel to select files and directories" +requirements = ["fd", "bat"] + +[source] +command = [ + { name = "Default", run = "fd -t f" }, + { name = "Hidden", run = "fd -t f -H" }, + { name = "Hidden + ignored", run = "fd -t f -H -I" }, +] + +[preview] +command = "bat -n --color=always '{}'" +env = { BAT_THEME = "ansi" } + +[keybindings] +shortcut = "f1" +f12 = "actions:edit" +ctrl-up = "actions:goto_parent_dir" + +[actions.edit] +description = "Opens the selected entries with the default editor (falls back to vim)" +command = "${EDITOR:-vim} {}" +shell = "bash" +# use `mode = "fork"` if you want to return to tv afterwards +mode = "execute" + +[actions.goto_parent_dir] +description = "Re-opens tv in the parent directory" +command = "tv files .." +mode = "execute" diff --git a/templates/television/cable/gh-prs.toml b/templates/television/cable/gh-prs.toml new file mode 100644 index 0000000..0a902e8 --- /dev/null +++ b/templates/television/cable/gh-prs.toml @@ -0,0 +1,55 @@ +[metadata] +name = "gh-prs" +description = "List GitHub PRs for the current repo" +requirements = ["gh", "jq"] + +[source] +command = '''gh pr list --state open --limit 100 --json number,title,createdAt,author,labels --jq 'sort_by(.createdAt) | reverse | .[] | " \u001b[32m#\(.number)\u001b[39m \(.title) \u001b[33m@\(.author.login)\u001b[39m" + (if (.labels | length) > 0 then " " + ([.labels[] | "\u001b[35m" + .name + "\u001b[39m"] | join(" ")) else "" end)' +''' +output = '{strip_ansi|split:#:1|split: :0}' +ansi = true + +[ui] +layout = "portrait" + +[preview] +command = '''gh pr view '{strip_ansi|split:#:1|split: :0}' --json number,title,body,state,headRefName,baseRefName,author,createdAt,updatedAt,mergeable,changedFiles,additions,deletions,labels,assignees,reviewDecision,headRepository,headRepositoryOwner | jq -r ' +" " + .title, +" #" + (.number | tostring), +"", +" \u001b[36mStatus:\u001b[39m \u001b[32m" + .state + "\u001b[39m " + .baseRefName + " ← " + .headRefName, +" \u001b[36mRepo:\u001b[39m \u001b[34m" + (.headRepositoryOwner.login) + "/" + (.headRepository.name) + "\u001b[39m", +" \u001b[36mAuthor:\u001b[39m \u001b[33m" + .author.login + "\u001b[39m", +" \u001b[36mCreated:\u001b[39m " + (.createdAt | fromdateiso8601 | (now - .) | if . < 3600 then (./60|floor|tostring) + " minutes ago" elif . < 86400 then (./3600|floor|tostring) + " hours ago" else (./86400|floor|tostring) + " days ago" end), +" \u001b[36mUpdated:\u001b[39m " + (.updatedAt | fromdateiso8601 | (now - .) | if . < 3600 then (./60|floor|tostring) + " minutes ago" elif . < 86400 then (./3600|floor|tostring) + " hours ago" else (./86400|floor|tostring) + " days ago" end), +(if (.labels | length) > 0 then " \u001b[36mLabels:\u001b[39m " + ([.labels[] | "\u001b[35m" + .name + "\u001b[39m"] | join(" ")) else "" end), +" \u001b[36mMerge Status:\u001b[39m " + (if .mergeable == "MERGEABLE" then "\u001b[32m✓ Clean\u001b[39m" elif .mergeable == "CONFLICTING" then "\u001b[31m✗ Dirty\u001b[39m" else "\u001b[33m? Unknown\u001b[39m" end), +" \u001b[36mChanges:\u001b[39m " + (.changedFiles | tostring) + " files \u001b[32m+" + (.additions | tostring) + "\u001b[39m \u001b[31m-" + (.deletions | tostring) + "\u001b[39m", +"", +" \u001b[90m────────────────────────────────────────────────────────────\u001b[39m", +"", +(.body // "")' +''' + +[keybindings] +enter = "actions:open" + +[actions.open] +description = "Open the PR in the browser" +command = "gh pr view {strip_ansi|split:#:1|split: :0} --web" +mode = "execute" + +[actions.checkout] +description = "Checkout the PR branch locally" +command = "gh pr checkout {strip_ansi|split:#:1|split: :0}" +mode = "execute" + +[actions.merge] +description = "Merge the selected PR" +command = "gh pr merge {strip_ansi|split:#:1|split: :0}" +mode = "execute" + +[actions.diff] +description = "View the PR diff" +command = "gh pr diff {strip_ansi|split:#:1|split: :0} | less" +mode = "execute" diff --git a/templates/television/cable/git-log.toml b/templates/television/cable/git-log.toml new file mode 100644 index 0000000..9f80a9f --- /dev/null +++ b/templates/television/cable/git-log.toml @@ -0,0 +1,34 @@ +[metadata] +name = "git-log" +description = "A channel to select from git log entries" +requirements = ["git"] + +[source] +command = "git log --graph --pretty=format:'%C(yellow)%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --color=always" +output = "{strip_ansi|split: :1}" +ansi = true +no_sort = true +frecency = false + +[preview] +command = "git show -p --stat --pretty=fuller --color=always '{strip_ansi|split: :1}' | head -n 1000" + +[keybindings] +ctrl-y = "actions:cherry-pick" +ctrl-r = "actions:revert" +ctrl-o = "actions:checkout" + +[actions.cherry-pick] +description = "Cherry-pick the selected commit" +command = "git cherry-pick '{strip_ansi|split: :1}'" +mode = "execute" + +[actions.revert] +description = "Revert the selected commit" +command = "git revert '{strip_ansi|split: :1}'" +mode = "execute" + +[actions.checkout] +description = "Checkout the selected commit" +command = "git checkout '{strip_ansi|split: :1}'" +mode = "execute" diff --git a/templates/television/cable/path.toml b/templates/television/cable/path.toml new file mode 100644 index 0000000..ec4bec2 --- /dev/null +++ b/templates/television/cable/path.toml @@ -0,0 +1,15 @@ +[metadata] +name = "path" +description = "Investigate PATH contents" +requirements = ["fd", "bat"] + +[source] +command = "printf '%s\n' \"$PATH\" | tr ':' '\n'" + +[preview] +command = "fd -tx -d1 . \"{}\" -X printf \"%s\n\" \"{/}\" | sort -f | bat -n --color=always" + +[actions.cd] +description = "Open a shell in the selected PATH directory" +command = "cd {} && $SHELL" +mode = "execute" diff --git a/templates/television/cable/recent-files.toml b/templates/television/cable/recent-files.toml new file mode 100644 index 0000000..e044bf7 --- /dev/null +++ b/templates/television/cable/recent-files.toml @@ -0,0 +1,23 @@ +[metadata] +name = "recent-files" +description = "List recently modified files (via git or filesystem)" +requirements = ["git", "bat"] + +[source] +command = [ + { name = "Recent", run = "git diff --name-only HEAD~10 HEAD 2>/dev/null || find . -type f -mtime -7 -not -path '*/.*' 2>/dev/null | head -100" }, + { name = "Last hour", run = "find . -type f -mmin -60 -not -path '*/.*' 2>/dev/null | head -100" }, +] + +[preview] +command = "bat -n --color=always '{}'" +env = { BAT_THEME = "ansi" } + +[keybindings] +enter = "actions:edit" + +[actions.edit] +description = "Open the selected file in editor" +command = "${EDITOR:-vim} {}" +shell = "bash" +mode = "execute" diff --git a/templates/television/cable/text.toml b/templates/television/cable/text.toml new file mode 100644 index 0000000..03eefd0 --- /dev/null +++ b/templates/television/cable/text.toml @@ -0,0 +1,36 @@ +[metadata] +name = "text" +description = "A channel to find and select text from files" +requirements = ["rg", "bat"] + +[source] +command = [ + { name = "Default", run = "rg . --no-heading --line-number --colors 'match:fg:white' --colors 'path:fg:blue' --color=always" }, + { name = "Hidden", run = "rg . --no-heading --line-number --colors 'match:fg:white' --colors 'path:fg:blue' --color=always --hidden" }, + { name = "Hidden + ignored", run = "rg . --no-heading --line-number --colors 'match:fg:white' --colors 'path:fg:blue' --color=always --hidden --no-ignore-vcs" }, +] +ansi = true +output = "{strip_ansi|split:\\::..2}" + +[preview] +command = "bat -n --color=always '{strip_ansi|split:\\::0}'" +env = { BAT_THEME = "ansi" } +offset = '{strip_ansi|split:\::1}' + +[ui] +preview_panel = { header = '{strip_ansi|split:\::..2}' } + +[keybindings] +enter = "actions:edit" + +[actions.edit] +description = "Open file in editor at line" +command = "${EDITOR:-vim} '+{strip_ansi|split:\\::1}' '{strip_ansi|split:\\::0}'" +shell = "bash" +mode = "execute" + +[actions.echo] +description = "Output the file and the line" +# command = "echo '{split:=:0}'" +command = "echo '{strip_ansi|split:\\::0}':'{strip_ansi|split:\\::1}'" +mode = "execute"