Skip to content

cd on quit

rovr can change the current directory to wherever you were when you quit using the --cwd-file CLI option.

The --cwd-file option writes the current working directory to a specified file when rovr exits:

Terminal window
# Create a temporary file and use it with rovr
cwd_file=$(mktemp -t rovr_cwd.XXXXXX)
rovr --cwd-file "$cwd_file"
cd "$(cat "$cwd_file")"
rm -f "$cwd_file"

You can create wrapper functions in your shell config for convenience:

rovr () {
local cwd_file=$(mktemp -t rovr_cwd.XXXXXX)
command rovr --cwd-file "$cwd_file" "$@"
if [ -f "$cwd_file" ]; then
local new_loc=$(cat "$cwd_file")
if [ -n "$new_loc" ] && [ "$new_loc" != "$PWD" ]; then
cd "$new_loc"
fi
rm -f "$cwd_file"
fi
}

rovr also supports other Yazi-style CLI options for direct integration with scripts and tools:

Write selected files to a specified file when rovr exits:

Terminal window
# Using a temporary file
chooser_file=$(mktemp -t rovr_selected.XXXXXX)
rovr --chooser-file "$chooser_file"
while IFS= read -r file; do
echo "Selected: $file"
done < "$chooser_file"
rm -f "$chooser_file"

You can use both options together:

Terminal window
# Using temporary files for both options
cwd_file=$(mktemp -t rovr_cwd.XXXXXX)
chooser_file=$(mktemp -t rovr_selected.XXXXXX)
rovr --cwd-file "$cwd_file" --chooser-file "$chooser_file"
# Process results
cd "$(cat "$cwd_file")"
while IFS= read -r file; do
echo "Selected: $file"
done < "$chooser_file"
# Clean up
rm -f "$cwd_file" "$chooser_file"

this is an example integration with helix

[keys.normal]
C-y = [
':open %sh{rovr %{buffer_name} --chooser-file=__stdout__ --force-tty}',
':redraw',
]

will not work

Both --chooser-file and --cwd-file lets you write to stdout and stderr.

To do so, wrap them with double underscores, and include --force-tty to ignore piping status

(rovr --chooser-file __stdout__ --force-tty) -split "`n" | ForEach-Object { Get-Item $_ }