Directory navigator
Go to file
Přemysl Eric Janouch 063938ff60
README.adoc: add configuration for fish
2020-10-01 04:04:19 +02:00
CMakeLists.txt Name change 2020-08-28 18:23:46 +02:00
LICENSE Always accept ^? as well as ^H as backspace 2020-09-21 21:15:15 +02:00
Makefile Mark files that make use of POSIX ACLs 2017-07-14 21:49:32 +02:00
README.adoc README.adoc: add configuration for fish 2020-10-01 04:04:19 +02:00
sdn.cpp Set cursor to child when going to parent dir 2020-09-29 03:39:13 +02:00
sdn.png Add screenshot to README 2018-11-02 21:19:41 +01:00

README.adoc

sdn

sdn is a simple directory navigator that you can invoke while editing shell commands. It enables you to:

  • take a quick peek at directory contents without running ls

  • browse the filesystem without all the mess that Midnight Commander does: theres no need to create a subshell in a new pty. The current command line can be simply forwarded if it is to be edited. Whats more, it will always be obvious whether the navigator is running.

The only supported platform is Linux. I wanted to try a different, simpler approach here, and the end result is very friendly to tinkering.

sdn

Building

Build dependencies: CMake and/or make, a C++14 compiler, pkg-config
Runtime dependencies: ncursesw, libacl

Unfortunately most LLVM libc++ versions have a bug that crashes sdn on start. Use GNU libstdc++ if youre affected.

$ git clone https://git.janouch.name/p/sdn.git
$ mkdir sdn/build
$ cd sdn/build
$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug
$ make

To install the application, you can do either the usual:

# make install

Or you can try telling CMake to make a package for you. For Debian it is:

$ cpack -G DEB
# dpkg -i sdn-*.deb

There is also a Makefile you can use to quickly build a binary to be copied into the PATH of any machine you want to have sdn on.

zsh

To start using this navigator, put the following in your .zshrc:

sdn-navigate () {
  # ... possibly zle-line-init
  while eval "`sdn`"; do
    [ -z "$cd" ] || cd "$cd"
    [ -z "$insert" ] || LBUFFER="$LBUFFER$insert "
    [ -z "$helper" ] && break
    eval "exec </dev/tty; $helper" || break
  zle reset-prompt
  # ... possibly zle-line-finish
}
zle -N sdn-navigate
bindkey '\eo' sdn-navigate

fish

To start using this navigator, put the following in your config.fish:

function sdn-navigate
	set --local IFS
	while eval (sdn | string replace -ar '^(.*?)=' 'set --$1 ')
		test -z "$cd" || cd "$cd"
		test -z "$insert" || commandline --insert "$insert "
		test -z "$helper" && break
		eval $helper || break
	end
	commandline --function repaint
end
bind \eo sdn-navigate

bash

Here we cant reset the prompt from within a bind -x handler but there is an acceptable workaround that sadly submits a blank line:

sdn-navigate () {
  SDN_L=$READLINE_LINE SDN_P=$READLINE_POINT
  READLINE_LINE=

  while eval "`sdn`"; do
    [[ -z "$cd" ]] || cd "$cd"
    [[ -z "$insert" ]] || {
      SDN_L="${SDN_L:0:$SDN_P}$insert ${SDN_L:$SDN_P}"
      ((SDN_P=SDN_P+${#insert}+1))
    }
    [[ -z "$helper" ]] && break
    eval "$helper" || break
  done
}
sdn-restore () {
  READLINE_LINE=$SDN_L READLINE_POINT=$SDN_P
  unset SDN_L SDN_P
}

bind -x '"\200": sdn-navigate'
bind -x '"\201": sdn-restore'
bind '"\eo":"\200\C-m\201"'

Colours

Here is an example of a ~/.config/sdn/look file; the format is similar to that of git, only named colours arent supported:

cursor 231 202
bar 16 255 ul
cwd bold
input

Filename colours are taken from the LS_COLORS environment variable. Run dircolors to get some defaults.

Bindings

To obtain more vifm-like controls, you may write the following to your ~/.config/sdn/bindings file:

normal h parent
normal l choose
normal ? help

Helper programs

The F3 and F4 keys are normally bound to actions view and edit, similarly to Norton Commander and other orthodox file managers. The helper programs used here may be changed by setting the PAGER and VISUAL (or EDITOR) environment variables.

While it is mostly possible to get mcview working using an invocation like PAGER='mcview -u' sdn, beware that this helper cannot read files from its standard input, nor does it enable overstrike processing by default (F9, could be hacked around in mc.ext by turning on the nroff switch for a custom file extension, just without actually invoking nroff), and thus it cant show the program help. sdn is currently optimised for less as the pager.

Similar software

  • https://elvish.io/ is an entire shell with an integrated ranger-like file manager on Ctrl-N (I find this confusing and resource-demanding, preferring to keep closer to "orthodox file managers")

Contributing and Support

Use https://git.janouch.name/p/sdn to report any bugs, request features, or submit pull requests. git send-email is tolerated. If you want to discuss the project, feel free to join me at ircs://irc.janouch.name, channel #dev.

Bitcoin donations are accepted at: 12r5uEWEgcHC46xd64tt3hHt9EUvYYDHe9

License

This software is released under the terms of the 0BSD license, the text of which is included within the package along with the list of authors.