2017-06-29 02:50:39 +02:00
|
|
|
sdn
|
|
|
|
===
|
|
|
|
:compact-option:
|
|
|
|
|
|
|
|
'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:
|
|
|
|
there's no need to create a subshell in a new pty. The current command line
|
|
|
|
can be simply forwarded if it is to be edited. What's more, it will always
|
|
|
|
be obvious whether the navigator is running.
|
|
|
|
|
2018-11-02 15:40:56 +01:00
|
|
|
The only supported platform is Linux. I wanted to try a different, simpler
|
|
|
|
approach here, and the end result is very friendly to tinkering.
|
2017-06-29 02:50:39 +02:00
|
|
|
|
2018-11-02 21:19:41 +01:00
|
|
|
image::sdn.png[align="center"]
|
|
|
|
|
2017-06-29 02:50:39 +02:00
|
|
|
Building
|
|
|
|
--------
|
|
|
|
Build dependencies: CMake and/or make, a C++14 compiler, pkg-config +
|
2018-11-02 21:19:41 +01:00
|
|
|
Runtime dependencies: ncursesw, libacl
|
2017-06-29 02:50:39 +02:00
|
|
|
|
2020-09-15 19:31:33 +02:00
|
|
|
// Working around libasciidoc's missing support for escaping it like \++
|
|
|
|
:doubleplus: ++
|
|
|
|
|
2018-11-03 17:04:50 +01:00
|
|
|
Unfortunately most LLVM libc++ versions have a bug that crashes 'sdn' on start.
|
2020-09-15 19:31:33 +02:00
|
|
|
Use GNU libstdc{doubleplus} if you're affected.
|
2018-11-03 17:04:50 +01:00
|
|
|
|
2020-08-28 18:24:06 +02:00
|
|
|
$ git clone https://git.janouch.name/p/sdn.git
|
2017-06-29 02:50:39 +02:00
|
|
|
$ 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.
|
|
|
|
|
2020-10-01 04:07:56 +02:00
|
|
|
Integration
|
|
|
|
-----------
|
|
|
|
|
2017-06-29 02:50:39 +02:00
|
|
|
zsh
|
2020-10-01 04:07:56 +02:00
|
|
|
~~~
|
2020-10-01 04:04:19 +02:00
|
|
|
To start using this navigator, put the following in your '.zshrc':
|
2020-08-28 18:30:49 +02:00
|
|
|
|
2020-10-01 04:17:22 +02:00
|
|
|
----
|
2017-06-30 22:51:52 +02:00
|
|
|
sdn-navigate () {
|
2020-10-04 14:20:10 +02:00
|
|
|
# ... possibly zle-line-finish
|
2020-10-01 11:54:01 +02:00
|
|
|
while eval "`sdn "$BUFFER" "$CURSOR"`"; do
|
2020-09-29 00:55:01 +02:00
|
|
|
[ -z "$cd" ] || cd "$cd"
|
|
|
|
[ -z "$insert" ] || LBUFFER="$LBUFFER$insert "
|
|
|
|
[ -z "$helper" ] && break
|
2020-10-01 15:24:25 +02:00
|
|
|
|
|
|
|
# Workaround for "zsh: suspended (tty output)" when invoking
|
|
|
|
# helpers after the terminal has been resized while running sdn
|
|
|
|
command true
|
|
|
|
|
2020-10-08 19:43:19 +02:00
|
|
|
/bin/sh -c "$helper" </dev/tty || break
|
2020-10-01 15:24:25 +02:00
|
|
|
done
|
2020-10-04 14:20:10 +02:00
|
|
|
# ... possibly zle-line-init
|
2017-06-30 22:55:18 +02:00
|
|
|
zle reset-prompt
|
2017-06-29 02:50:39 +02:00
|
|
|
}
|
2017-06-30 22:51:52 +02:00
|
|
|
zle -N sdn-navigate
|
|
|
|
bindkey '\eo' sdn-navigate
|
2020-10-01 04:17:22 +02:00
|
|
|
----
|
2017-06-29 02:50:39 +02:00
|
|
|
|
2017-06-30 22:51:52 +02:00
|
|
|
bash
|
2020-10-01 04:07:56 +02:00
|
|
|
~~~~
|
2020-10-01 08:36:31 +02:00
|
|
|
Here we can't make the shell update the prompt on directory changes since
|
|
|
|
there's no way to invoke `prompt_again()` from a `bind -x` handler but we can
|
|
|
|
work around it by submitting a blank line:
|
2020-08-28 18:30:49 +02:00
|
|
|
|
2020-10-01 04:17:22 +02:00
|
|
|
----
|
2020-10-20 03:42:14 +02:00
|
|
|
sdn-cursor () {
|
|
|
|
if [[ $BASH_VERSINFO -lt 5 ]]
|
|
|
|
then echo -n "$SDN_L" | wc -m
|
|
|
|
else echo "$SDN_P"
|
|
|
|
fi
|
|
|
|
}
|
2017-06-30 22:51:52 +02:00
|
|
|
sdn-navigate () {
|
2017-06-30 22:55:18 +02:00
|
|
|
SDN_L=$READLINE_LINE SDN_P=$READLINE_POINT
|
|
|
|
READLINE_LINE=
|
|
|
|
|
2020-10-20 03:42:14 +02:00
|
|
|
while eval "`sdn "$SDN_L" "$(sdn-cursor)"`"; do
|
2020-09-29 00:55:01 +02:00
|
|
|
[[ -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
|
2020-10-08 19:43:19 +02:00
|
|
|
/bin/sh -c "$helper" || break
|
2020-09-29 00:55:01 +02:00
|
|
|
done
|
2017-06-30 22:51:52 +02:00
|
|
|
}
|
|
|
|
sdn-restore () {
|
2017-06-30 22:55:18 +02:00
|
|
|
READLINE_LINE=$SDN_L READLINE_POINT=$SDN_P
|
|
|
|
unset SDN_L SDN_P
|
2017-06-30 22:51:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bind -x '"\200": sdn-navigate'
|
|
|
|
bind -x '"\201": sdn-restore'
|
|
|
|
bind '"\eo":"\200\C-m\201"'
|
2020-10-01 04:17:22 +02:00
|
|
|
----
|
2017-06-29 02:50:39 +02:00
|
|
|
|
2020-10-20 03:47:12 +02:00
|
|
|
fish
|
|
|
|
~~~~
|
|
|
|
To start using this navigator, put the following in your 'config.fish':
|
|
|
|
|
|
|
|
----
|
|
|
|
function sdn-navigate
|
|
|
|
set --local IFS
|
|
|
|
set --local buffer (commandline)
|
|
|
|
set --local cursor (commandline --cursor)
|
|
|
|
while eval (sdn $buffer $cursor | string replace -ar '^(.*?)=' 'set --$1 ')
|
|
|
|
test -z "$cd" || cd "$cd"
|
|
|
|
test -z "$insert" || commandline --insert "$insert "
|
|
|
|
test -z "$helper" && break
|
|
|
|
/bin/sh -c "$helper" || break
|
|
|
|
end
|
|
|
|
commandline --function repaint
|
|
|
|
end
|
|
|
|
bind \eo sdn-navigate
|
|
|
|
----
|
|
|
|
|
2020-10-07 20:49:58 +02:00
|
|
|
elvish
|
|
|
|
~~~~~~
|
|
|
|
To start using this navigator, put the following in your 'rc.elv':
|
|
|
|
|
|
|
|
----
|
|
|
|
use str
|
|
|
|
edit:insert:binding[Alt-o] = {
|
|
|
|
local:reesc = [posix]{ str:replace "'\\''" "''" $posix }
|
2020-10-08 19:43:19 +02:00
|
|
|
local:posix = [cmd]{ /bin/sh -c $cmd </dev/tty >/dev/tty 2>&1 }
|
2020-10-07 20:49:58 +02:00
|
|
|
|
|
|
|
# XXX: the -dot is not a stable API, and may hence break soon
|
|
|
|
local:buffer = $edit:current-command
|
|
|
|
local:cursor = (str:to-codepoints $buffer[0..$edit:-dot] | count)
|
|
|
|
local:ns = (ns [&])
|
|
|
|
while ?(eval ($reesc (sdn $buffer $cursor |
|
|
|
|
sed 's/^local //' | slurp)) &ns=$ns) {
|
|
|
|
if (not-eq $ns[cd] "") { cd $ns[cd] }
|
|
|
|
if (not-eq $ns[insert] "") { edit:insert-at-dot $ns[insert]" " }
|
|
|
|
if (or (eq $ns[helper] "") (not ?($posix $ns[helper]))) { break }
|
|
|
|
}
|
|
|
|
edit:redraw &full=$true
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
This shell is absolutely perverse. And so is integrating 'sdn' into it because
|
|
|
|
it already includes a custom file manager, bound to Ctrl-N (though I find
|
|
|
|
the ranger-like interface confusing and resource-demanding). Version 0.14.1 or
|
|
|
|
newer is required.
|
|
|
|
|
2020-10-01 04:07:56 +02:00
|
|
|
Configuration
|
|
|
|
-------------
|
|
|
|
|
2020-09-28 21:18:08 +02:00
|
|
|
Colours
|
2020-10-01 04:07:56 +02:00
|
|
|
~~~~~~~
|
2017-06-30 21:29:10 +02:00
|
|
|
Here is an example of a '~/.config/sdn/look' file; the format is similar to
|
2020-09-28 21:18:08 +02:00
|
|
|
that of git, only named colours aren't supported:
|
2020-08-28 18:30:49 +02:00
|
|
|
|
2020-08-28 18:33:08 +02:00
|
|
|
....
|
2017-06-30 21:29:10 +02:00
|
|
|
cursor 231 202
|
|
|
|
bar 16 255 ul
|
|
|
|
cwd bold
|
|
|
|
input
|
2020-10-01 13:31:39 +02:00
|
|
|
cmdline 145
|
2020-08-28 18:33:08 +02:00
|
|
|
....
|
2020-08-28 18:30:49 +02:00
|
|
|
|
2020-09-28 21:18:08 +02:00
|
|
|
Filename colours are taken from the `LS_COLORS` environment variable.
|
2018-11-03 17:04:50 +01:00
|
|
|
Run `dircolors` to get some defaults.
|
2017-06-30 21:29:10 +02:00
|
|
|
|
2020-09-15 19:36:19 +02:00
|
|
|
Bindings
|
2020-10-01 04:07:56 +02:00
|
|
|
~~~~~~~~
|
2020-09-15 19:36:19 +02:00
|
|
|
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
|
|
|
|
....
|
|
|
|
|
2020-09-28 21:18:08 +02:00
|
|
|
Helper programs
|
2020-10-01 04:07:56 +02:00
|
|
|
~~~~~~~~~~~~~~~
|
2020-09-28 21:18:08 +02:00
|
|
|
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 can't show the
|
|
|
|
program help. 'sdn' is currently optimised for 'less' as the pager.
|
|
|
|
|
2017-06-29 02:50:39 +02:00
|
|
|
Contributing and Support
|
|
|
|
------------------------
|
2018-06-22 15:39:38 +02:00
|
|
|
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.
|
2017-06-29 02:50:39 +02:00
|
|
|
|
2018-06-22 15:39:38 +02:00
|
|
|
Bitcoin donations are accepted at: 12r5uEWEgcHC46xd64tt3hHt9EUvYYDHe9
|
2017-06-29 02:50:39 +02:00
|
|
|
|
|
|
|
License
|
|
|
|
-------
|
2018-06-22 15:35:58 +02:00
|
|
|
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.
|