Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/const.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { xdgConfig } from 'xdg-basedir'
import { join as joinPath } from '@std/path'

export const XDG_CONFIG_HOME = xdgConfig ?? Deno.makeTempDirSync()
export const WK_CONFIG_HOME = joinPath(xdgConfig ?? Deno.makeTempDirSync(), 'wk')

export const PRINTABLE_ASCII = /^[ -~]$/
12 changes: 5 additions & 7 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command, EnumType } from '@cliffy/command'
import { join as joinPath } from '@std/path'
import { parse as parseYaml } from '@std/yaml'
import { Binding } from './types/Binding.ts'
import { XDG_CONFIG_HOME } from './const.ts'
import { WK_CONFIG_HOME } from './const.ts'
import { TUI } from './tui.ts'
import { defaultContext, mergeContext, PartialContext } from './types/Context.ts'
import { Dependencies, main } from './main.ts'
Expand Down Expand Up @@ -31,19 +31,17 @@ For example, this simulates pressing "g", "p", and "f".`,
)
.action(async ({ upOneLine, inputs }) => {
const fetchContextWaiting = (async () => {
const found = await loadYaml<PartialContext>(joinPath(XDG_CONFIG_HOME, 'wk', 'config.yaml')).catch(() =>
undefined
)
const found = await loadYaml<PartialContext>(joinPath(WK_CONFIG_HOME, 'config.yaml')).catch(() => undefined)
if (found === undefined) {
return defaultContext
}
return mergeContext(found)
})()

const fetchBindingsWaiting = Promise.all([
loadYaml<Binding[]>(joinPath(XDG_CONFIG_HOME, 'wk', 'bindings.yaml')).catch(() => []).catch(() => []),
loadYaml<Binding[]>(joinPath(Deno.cwd(), 'wk.bindings.yaml')).catch(() => []).catch(() => []),
]).then(([globalBindings, localBindings]) => [...globalBindings, ...localBindings])
loadYaml<Binding[]>(joinPath(WK_CONFIG_HOME, 'bindings.yaml')).catch(() => [] as Binding[]),
loadYaml<Binding[]>(joinPath(Deno.cwd(), 'wk.bindings.yaml')).catch(() => [] as Binding[]),
]).then(([globalBindings, localBindings]) => globalBindings.concat(localBindings))

const tty = await Deno.open('/dev/tty', { read: true, write: true })
const tui = new TUI(tty, inputs === undefined ? [] : inputs.split(' ').map(unescapeAnsi))
Expand Down
4 changes: 2 additions & 2 deletions src/widget.eta
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ _wk_widget() {
;;
esac

# `p` flag does NOT work with the ${var} format; must use $var instead.
# See: https://zsh.sourceforge.io/Doc/Release/Expansion.html#Parameter-Expansion
<%- /* `p` flag does NOT work with the ${var} format; must use $var instead. */ _%>
<%- /* See: https://zsh.sourceforge.io/Doc/Release/Expansion.html#Parameter-Expansion */ _%>
local delimiter=$res[1]
reply=("${(@ps:$delimiter:)${res:2}}")

Expand Down