Last active
June 22, 2025 14:12
-
-
Save YPares/c6d203e4e899ea3ed33bc62ff6a81dea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std/dirs | |
def "path shorten" [--last] { | |
str replace $env.HOME "~" | if $last { | |
path split | last | |
} else { $in } | |
} | |
def --env "dirs reset-current" [] { | |
cd ($env.DIRS_LIST | get $env.DIRS_POSITION) | |
} | |
$env.PROMPT_COMMAND = { | |
dirs | each {|d| | |
let color = if $d.active { | |
if $d.path == ($env.DIRS_LIST | get $env.DIRS_POSITION) { | |
"light_green" | |
} else {"yellow"} | |
} else {"default_dimmed"} | |
$d.path | path shorten --last | | |
$"(ansi ($color))($in)(ansi reset)" | |
} | | |
str join $"(ansi yellow)|(ansi reset)" | | |
$"(ansi reset)($in)" | |
} | |
$env.TRANSIENT_PROMPT_COMMAND = { | |
$env.PWD | path shorten | |
} | |
def select-paths [] { | |
each {|p| | |
let type = $p | path type | |
let clr = if $type == "dir" {"blue"} else {"default"} | |
[ $"(ansi $clr)($p)(ansi reset)(char fs)" | |
$"(ansi attr_dimmed)(ansi attr_italic)($type)(ansi reset)" | |
] | str join " " | |
} | | |
str join "\n" | ( | |
fzf --height=40 --reverse --style minimal --info inline-right | |
--ansi --color "pointer:blue,marker:green" | |
--tiebreak begin | |
--multi | |
--delimiter (char fs) --with-nth 1 --accept-nth 1 | |
--bind "ctrl-f:down,ctrl-r:up,ctrl-space:accept,ctrl-z:abort,backward-eof:abort" | |
--bind "ctrl-a:select-all" | |
) | lines | |
} | |
def select-glob-out [] { | |
path relative-to $env.PWD | | |
where {is-not-empty} | | |
select-paths | | |
path expand -n | |
} | |
$env.config.keybindings ++= [ | |
[control_alt left | |
{send: executehostcommand, cmd: 'dirs prev'} | |
] | |
[control_alt right | |
{send: executehostcommand, cmd: 'dirs next'} | |
] | |
[control_alt up | |
{send: executehostcommand, cmd: 'cd ..'} | |
] | |
[control_alt down | |
{send: executehostcommand, cmd: 'dirs reset-current'} | |
] | |
[control_alt char_d | |
{send: executehostcommand, cmd: 'dirs drop'} | |
] | |
[alt char_d | |
{ | |
send: executehostcommand | |
cmd: 'let ds = glob -F **/* | select-glob-out; | |
dirs reset-current; | |
if ($ds | length) > 0 {dirs add ...$ds}' | |
} | |
] | |
] | each { | |
{mode: emacs, modifier: $in.0, keycode: $in.1, event: $in.2} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment