Skip to content

[feat request]: command to open an interactive file manager and dust #506

@juanMarinero

Description

@juanMarinero

dust is awesome, but not dynamic like a file manager. One can take advantage of both if:

  • one terminal window shows the dust tree
  • the other window runs a file manager, that sorts by size is ideal like ncdu

Next is my proposal, though it just works using kitty and zsh.

Request:

  • Improve and provide alike next command in this repo
  • Expand for other shells, terminals and file-managers

Image

#!/usr/bin/env zsh

_du() {

  dust -r

  unset answer_du && echo -n "Navigate dirs with ncdu? (y/N):  "
  read answer_du
  answer_du=${answer_du:-n} # Default to 'n' if no input is provided
  echo
  if [[ "$answer_du" == "n" ]]; then
    return
  fi

  _kitty_vwindow_new "dust -r" "_du_ncdu"
}
_du_ncdu() {
  sleep 1
  # flags: https://dev.yorhel.nl/ncdu/man
  ncdu --color dark-bg --show-percent --show-itemcount --follow-symlinks --confirm-delete
}
_kitty_vwindow_new() {
  if [ $# -lt 1 ]; then
    echo "Error: Missing arguments"
    echo "Usage: x_kitty_vwindow_new <right_cmd> <left_cmd>"
    return 1
  fi
  local right_cmd="$1"
  local left_cmd="$2"

  # Create new window
  kitty @ launch\
    --type=window \
    --keep-focus \
    --hold zsh -c "source ~/.zshrc && cd $PWD && $right_cmd; exec zsh"

  # Run left command if any
  if [ -n "$left_cmd" ]; then
    $left_cmd
  fi
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions