Commit Graph

420 Commits

Author SHA1 Message Date
Arun Prakash Jana 928699d4a4
float is suficient and a _little_ faster in coolsize() 2018-03-05 08:46:34 +05:30
Arun Prakash Jana 4d93a7f9fe Revert "Integer-only coolsize() (#84)"
This reverts commit 7be0726164.
2018-03-05 01:12:10 +05:30
Arun Prakash Jana 58d90bfcf6 Revert "fix rounding carry in coolsize() (#91)"
This reverts commit 7654a2e0c6.
2018-03-05 01:11:29 +05:30
Arun Prakash Jana 90e8b81c3e Revert "Fix compilation warning"
This reverts commit 30fdb6ff11.
2018-03-05 01:11:14 +05:30
Arun Prakash Jana 30fdb6ff11
Fix compilation warning 2018-03-05 00:57:31 +05:30
Alex Suykov 7654a2e0c6 fix rounding carry in coolsize() (#91)
Sizes like 1.999 get rounded to (1 + 100/100), which should be displayed
as 2.00 not 1.100 as simple %i.%02i would do without additional measures.
2018-03-05 00:48:10 +05:30
Arun Prakash Jana 3036b8a733
Fix #89: User-specific tmp file for copying filenames
Use distinct (by username) tmp filename to copy file paths.

The pattern used is:
/tmp/nnncp$USER

If username is 'arun', the file name is `/tmp/nnncparun`.
2018-03-04 10:37:18 +05:30
Arun Prakash Jana 43134cdfa8
Support ~, - and & keyboard shortcuts at the bookmark prompt.
In nav-as-you-type mode only control keys are understood when filter is enabled.
We need some way to quicly jump HOME, last visited dir or start dir.
2018-03-03 19:19:06 +05:30
Arun Prakash Jana 10e84a28ed
Both src and dst should be alignment checked separately
The following pattern passes the current check:

src  - 1010
dst  - 0101
mask - 1111
2018-03-03 01:08:15 +05:30
Alex Suykov 7be0726164 Integer-only coolsize() (#84) 2018-03-01 13:22:25 +05:30
Arun Prakash Jana 0f89943d95
Prepare for release v1.7 2018-02-28 01:54:42 +05:30
Arun Prakash Jana 11dac5e3db
Add shortcut ^G to quit and cd 2018-02-24 22:54:54 +05:30
Arun Prakash Jana 58e27fb2de
Use macros for external utils 2018-02-24 20:45:50 +05:30
Arun Prakash Jana ee733a39b1
Support batch file rename in vidir 2018-02-24 19:46:58 +05:30
Arun Prakash Jana a963d166c8
Enable file extract in nav-as-you-type mode 2018-02-24 10:43:06 +05:30
Arun Prakash Jana b22d8c32f9
Support file path copy when X is unavailable 2018-02-24 07:49:59 +05:30
Arun Prakash Jana 035bcdb198
Re-populate after spawning shell 2018-02-15 19:21:58 +05:30
Arun Prakash Jana af35b8a27c
Start dir watch, preserve cur entry when navigate-as-you-type is disabled 2018-02-13 13:28:18 +05:30
Arun Prakash Jana 19e5990d3a
Better message for multi-copy 2018-02-04 22:54:58 +05:30
Arun Prakash Jana 991ef57340
Do not show quotes on ^K 2018-01-29 20:49:38 +05:30
Arun Prakash Jana 1d067df0b5
Show copymode on/off 2018-01-28 12:44:29 +05:30
Arun Prakash Jana 1f87bb3bcb
Interpret ^T in filter mode 2018-01-28 12:23:23 +05:30
Arun Prakash Jana d48e91f011
Support file path quote on single copy 2018-01-28 12:04:56 +05:30
Arun Prakash Jana 6da9d5f499 Support file path quote on copy 2018-01-28 11:34:18 +05:30
Arun Prakash Jana e797a7eefd
Use macro for CRC8 table length 2018-01-19 20:39:23 +05:30
Arun Prakash Jana 98c79a69b5
Redraw if no entries when navigate-as-you-type is turned off
The main reason to do this is to start watching the current dir for changes. In
any case, this does not harm; if there are dir entries shown on redraw that's
better than showing nothing.
2018-01-17 20:22:07 +05:30
Arun Prakash Jana cbfeec5625
keybind to pin current dir - b 2018-01-17 19:32:22 +05:30
Arun Prakash Jana e359f60294
Set to last selection if filter is empty 2018-01-14 14:05:19 +05:30
Arun Prakash Jana bac199d0cf
Use consistent date format 2018-01-14 12:43:20 +05:30
Arun Prakash Jana 9f4199481a
Improve common message handling 2018-01-14 12:11:46 +05:30
Arun Prakash Jana 9bcca1a45c
Use concise and lowercase messages 2018-01-14 10:20:41 +05:30
Arun Prakash Jana e6580c38bf
Replace snprintf() with xstrlcpy() 2018-01-14 03:27:24 +05:30
Arun Prakash Jana a40d29ba9f
Support multiple file path copy
Design overview:

We are introducing multiple file path copy as a mode which can be toggled using
the keybind `^Y`. `^K` works as the individual entry selector. If the user wants
to select a range, (s)he can press `^Y` on the first entry and `^Y` on the last
entry.

We subscribe to notifications, so we need a fail-proof way to detect changes in
the directory contents. For example, if a file is deleted, it becomes difficult
to get the names of all the files in a range containing that file. If the file
is on a range boundary it would lead to wrong calculations. To handle this the
right way we use CRC8 checksum of all the visible entries in the directory. The
checksum is calculated based on the file information buffer. If the CRC changes
on a redraw(), we reset the multi-select mode.

New line (`\n`) works as the delimiter between file paths. Note that you may have
to disable IFS in the `NNN_COPIER` script to show file paths separated by spaces.
2018-01-14 01:43:30 +05:30
Arun Prakash Jana 4800250814
Key changes: ^F - extract archive, ^X - quit 2018-01-13 09:28:29 +05:30
Arun Prakash Jana 34b650aac8
Remap ^S and ^Q.
The replacement keys are:

^J - toggle du mode
^Y - quit

The change is done because ^S, ^Q keybinds are lost in the following case:
- start nnn
- navigate to a different directory
- spawn a shell
- exit the shell

The issue happens only with the 'special' keybinds like ^S, ^Q, ^Z... which get
their original shell interpretation back.

So we are replacing these 2 keybinds with 2 'non-special' combinations.
2018-01-09 14:21:09 +05:30
Arun Prakash Jana 827f7fd662
Sufficient to use refresh() after exitcurses() 2018-01-09 13:32:57 +05:30
Arun Prakash Jana 0a1776e18e
Add shortcut ^S to toggle du mode 2018-01-09 00:31:15 +05:30
Arun Prakash Jana f6fd15e088
Explicitly optimize modulo ops 2018-01-09 00:13:11 +05:30
Arun Prakash Jana 77fec499cb
Open with GUI app - Suppress stdout, stderr 2018-01-08 03:27:41 +05:30
Arun Prakash Jana 9cded0be0e
Simplify detail printing 2018-01-07 20:08:59 +05:30
Arun Prakash Jana afb6a7ab04
Change bookmark prompt and pin dir keys.
New keys:

- bookmark prompt (^B)
- pin directory (B)

The intention of the change is to facilitate opening the bookmark prompt in
navigate-as-you-type mode. The bookmark prompt is used more than the pin
current directory option.
2018-01-07 09:14:25 +05:30
Arun Prakash Jana f7c5a2924d
Highest priority to desktop search, rename 2018-01-07 03:27:09 +05:30
Arun Prakash Jana 2e7722976b
Enable extra shortcuts in navigate-as-you-type mode
Enabled functionality:

- Copy file path (^K)
- Run desktop search utility (^/)
- Rename file (^R)
- Open with... (^O)
- Pin current directory (^B)
- Visit pinned directory (^V)
- Extract archive (^X)
2018-01-06 11:58:01 +05:30
Arun Prakash Jana 542fd2f6e8
Swap weekday and month 2018-01-06 10:01:54 +05:30
Arun Prakash Jana d69365ff3e
Use a date format string 2018-01-06 03:59:36 +05:30
Arun Prakash Jana 5876c61f4c
Rearrange date format in file details 2018-01-06 03:56:09 +05:30
codeliveroil 915df53a04 Use standard date formats. (#74)
- For standard view, use ISO 8601 date format.
- For detailed view (i.e. stat), use default Linux date
  format. Also, remove GMT offset to avoid confusion in
  determining source of offset when reading alongside
  the local time zone.
2018-01-06 03:49:27 +05:30
Arun Prakash Jana fd11b53b4e
Show target for symlinks 2018-01-06 03:46:44 +05:30
Arun Prakash Jana 00533546d4
The *alloc() family is aligned 2018-01-04 17:46:06 +05:30
Arun Prakash Jana 242e22eb2d
Wrap realloc() to return aligned address 2018-01-04 06:23:20 +05:30
Arun Prakash Jana da7e30cd6f
Use aligned large buffers 2017-12-30 13:54:49 +05:30
Arun Prakash Jana 3a88e31a0e
Check alignment and enable -O3 2017-12-29 11:08:07 +05:30
Arun Prakash Jana 9b010b1c03 Fix checkpatch reports 2017-12-28 01:48:12 +05:30
Daniel Lockyer 77b0fe0104 Free allocated resources using regfree (#71) 2017-12-27 16:06:57 +05:30
Arun Prakash Jana 26e739a6d9
Use ffs() tweak. 2017-12-27 09:53:11 +05:30
Arun Prakash Jana ff1c467285
Explicitly cast opaque types 2017-12-27 00:49:43 +05:30
Arun Prakash Jana f1f2a53dbf TAB is not identified on OS X 2017-12-27 00:16:56 +05:30
Dmitri Goutnik 4dca8d7cf9 Lookup xdg-open in PATH on non-Apple platforms (#70) 2017-12-26 23:53:20 +05:30
Arun Prakash Jana 9bfc2fdc29
Use ffs() instead of ffsl() 2017-12-26 23:33:32 +05:30
Dmitri Goutnik c5f19ddd92 Fix compiler warnings on FreeBSD 11.x (#69) 2017-12-26 21:22:45 +05:30
Arun Prakash Jana 9b72fcba03
Replace getorder() by ffsl() 2017-12-25 23:27:37 +05:30
Arun Prakash Jana cd177086ca
OpenSUSE gcc fails at '-fno-tree-loop-vectorize' 2017-12-25 19:10:20 +05:30
Arun Prakash Jana f687463574
Prepare for release v1.6 2017-12-25 17:13:25 +05:30
Arun Prakash Jana 7f804ca8f2
Support 'Open with...' 2017-12-25 15:55:53 +05:30
Arun Prakash Jana f7399b05f9
Optimize xmemrchr() 2017-12-25 01:44:48 +05:30
Arun Prakash Jana 436d2143fd
Reduce sprintf() family usage 2017-12-25 00:28:12 +05:30
Arun Prakash Jana c0255db4f1
Optimize saving, matching old entry 2017-12-24 23:23:52 +05:30
Arun Prakash Jana 78f544c41d
Shorten error messages 2017-12-24 21:22:54 +05:30
Arun Prakash Jana f2387898f3
Limit filter length to NAME_MAX from LINE_MAX 2017-12-24 21:20:36 +05:30
Arun Prakash Jana 959db96f99
Use const if applicable 2017-12-24 21:03:23 +05:30
Arun Prakash Jana 8b98df0be1
Update documentation 2017-12-24 18:46:56 +05:30
Arun Prakash Jana 8189411aef
Users understand 'DIR' easier then 'cwd' 2017-12-24 15:23:33 +05:30
Arun Prakash Jana d9537e6d49
Add option -b to open bookmark directly 2017-12-24 15:21:38 +05:30
Arun Prakash Jana d3797f21d1
Order numeric file names (helps with /proc) 2017-12-24 03:15:22 +05:30
Arun Prakash Jana 59ae6c9e7f
Replace xstricmp() with strcoll() 2017-12-22 01:19:32 +05:30
Arun Prakash Jana a451e74465
Remove redundant variable 2017-12-22 00:58:02 +05:30
Arun Prakash Jana 04bf7537e5
Consider only symbolic or only nunmeric names 2017-12-22 00:56:15 +05:30
Arun Prakash Jana 2f86e0d107
No need to test end of numeric 2017-12-21 19:12:12 +05:30
Arun Prakash Jana 988a3dd621
Ignore punctuation marks in file name compare. Fix xstrcmp().
1. File name comparison method:
 - initially ignore white space and punctuation characters
 - run test for numeric values
 - if the remaining substrings match in case-insensitive compare, compare case
 - if they still match, see which one has more prefix symbols
 - if they still match, run a case-sensitive compare on complete strings

2. Fixed xstrcmp() to return diff instead of 0 and -1.
2017-12-21 17:49:31 +05:30
Arun Prakash Jana 0945dfb91a
Add file name len to entry structure 2017-12-20 22:20:28 +05:30
Arun Prakash Jana bc1e74bc56
Offset can be derived 2017-12-20 08:18:37 +05:30
Arun Prakash Jana 106c7c2371
Retire redundant variable 2017-12-20 00:42:11 +05:30
Arun Prakash Jana d135af33af
A fancier func to get order of 2 2017-12-20 00:01:32 +05:30
Arun Prakash Jana cc1891d351
Replace a large buf with global g_buf 2017-12-19 23:33:27 +05:30
Arun Prakash Jana ded690c693
Use exact number of bytes for each filename.
Results in even less memory usage. The names are appended one after another.
The offsets are reset when the location of the memory changes die to realloc().

Other changes:

1. Use a debug mode print to measure time.
2. Remove redundant prefix when printing pointers in debug mode.
2017-12-19 01:16:03 +05:30
Arun Prakash Jana 8307bc95bd
Fix #64: change printf() to printw() 2017-12-18 00:30:48 +05:30
Arun Prakash Jana ca28580746
NAME_MAX does not include NULL char 2017-12-18 00:00:08 +05:30
Arun Prakash Jana 7a16440e1f
An even faster nnn - no more copying file names!
nnn has been using `struct entry` to hold both file name as well as file info.

The design forces file names to be copied in the following cases:

 - swaps during file sort (nnn uses quicksort) applied after all the matching
   files are read (in no particular order; good old readdir()) into memory.
 - swaps during manual filtering. nnn moves non-matching entries below so they
   are not encountered twice resulting in fast filtering.

There were scopes for _massive_ improvements in this area. So I did what had to
be done - decouple the file names from `struct entry` and use a separate struct
to hold the names with the indices set when the files are added by opendir().

There was a hidden problem to this approach - nnn uses realloc() to allocate
memory for file information and realloc() may move the original pointer in mem
when it can't fit the new memory to the earlier pointer. To handle that the new
algorithm tracks the change in memory location and re-adjusts the existing dir
entry names when that happens; this too, without any copying!

Though the results seem pretty clean from a theoretical point of view and early
tests, we may uncover some bugs. However, the speed is just mind-blowing!

And the binary size remains the same too!!!
2017-12-17 23:08:55 +05:30
Arun Prakash Jana ef3eab073e
Fix indentation 2017-12-14 19:17:29 +05:30
Arun Prakash Jana c3545dd82f
Use static vars in frequently used APIs 2017-12-13 02:41:30 +05:30
Arun Prakash Jana 5ae9993a12
Retire redundant tmp vars 2017-12-13 02:32:45 +05:30
Arun Prakash Jana 1b035d6ffd
Process keypress by probable frequency 2017-12-13 01:46:50 +05:30
Arun Prakash Jana 6ccb8ee94b
Minor optimization, refactor 2017-12-04 19:52:35 +05:30
Arun Prakash Jana 092cdf3f82
Fix -Os compilation warnings 2017-12-03 17:36:00 +05:30
Arun Prakash Jana cd2bdc5991 Minor changes 2017-11-30 18:24:28 +05:30
Arun Prakash Jana 55abc13cd2
Minor maintenance 2017-10-16 05:24:56 +05:30
Arun Prakash Jana f1a27e21af
Ignore TAB in input prompt 2017-10-09 22:55:44 +05:30
Vlad Glagolev 9638ed148d Fix a couple of warnings on BSDs (#54) 2017-10-09 07:47:02 +05:30
Vlad Glagolev d835f72c6c Fix segfault when SHLVL env var is not available (#52) 2017-10-08 09:32:29 +05:30
Vlad Glagolev 8959a5b57d Correct name checking for NEW and RENAME (#53) 2017-10-08 09:17:32 +05:30
Vlad Glagolev caf368f593 OpenBSD compatibility support (#48)
* Improve compatibility with OpenBSD

* Fix indefinite blocking
2017-10-08 07:12:12 +05:30
maxice8 935fca41f1 include sys/types.h for non-glibc linux builds (#46) 2017-10-05 13:04:18 +05:30
Arun Prakash Jana dcf8fbf78b
Prepare for release v1.5 2017-10-05 00:18:53 +05:30
Arun Prakash Jana d62ce4bb5e
Remove redundant conversion 2017-10-01 18:59:43 +05:30
Arun Prakash Jana c66c941a97
Disable noti subscription for the same dir 2017-10-01 16:13:35 +05:30
Arun Prakash Jana 79cbc40a7f
Change archive list shortcut to 'F' 2017-10-01 04:28:48 +05:30
Arun Prakash Jana 6bfbff9519
Revert "Archive handling on OS X using unar+lsar"
This reverts commit 1e859eb1370bd67cecd06b7bc8c6f885b80554bd.
We will use atool on OS X as well, it can be brewed easily.
2017-09-27 22:14:09 +05:30
Arun Prakash Jana 7c54f073fc
Archive handling on OS X using unar+lsar 2017-09-27 22:14:07 +05:30
Arun Prakash Jana 71d27de517
Support archive listing and extraction 2017-09-27 22:14:01 +05:30
Arun Prakash Jana a594c876be
Show current entry number in du mode 2017-09-27 17:37:36 +05:30
Arun Prakash Jana 082974dc8e
Show current entry number.
...because you need to know where you are.
2017-09-27 02:08:58 +05:30
Arun Prakash Jana bc76c0f7ee
Fix #42 2017-09-24 23:46:34 +05:30
Arun Prakash Jana 55643a5fcc
Update NNN_NOWAIT changes 2017-09-19 19:55:02 +05:30
Paul df4b557ca1 Prevent nnn from waiting on open file process (#40)
* Prevent nnn from waiting on open file process

* Add env var flag to not wait for child process when opening file

* Set nowait flag once to skip bit-or every time we open a file

* Add documentation for NNN_NOWAIT
2017-09-19 12:00:54 +05:30
Arun Prakash Jana 968beb434a
Skip entries in case fstatat() fails, do not exit 2017-09-13 18:44:27 +05:30
Arun Prakash Jana 28f69e59fa
Support file and dir create 2017-09-10 13:05:25 +05:30
Arun Prakash Jana 5ab6dd2fed
Convert metaviewer and color to bitfields 2017-09-09 02:16:10 +05:30
Arun Prakash Jana 321a618192
Add general info in help 2017-09-09 01:10:21 +05:30
Arun Prakash Jana 91ab00061c
Prepare for v1.4 release 2017-09-04 10:23:02 +05:30
Arun Prakash Jana c35c1afa87
Reorder APIs 2017-09-02 14:09:34 +05:30
Arun Prakash Jana 056a79635a
Disable dircolor if no sub-directories
Fix regression from 1e5a0b8c5b.
2017-09-02 14:02:29 +05:30
Arun Prakash Jana 277cf66097
Move config.h to nnn.h 2017-09-02 11:39:44 +05:30
Arun Prakash Jana e2fae851c3
Use 'pin' dir instead of 'mark' dir 2017-09-01 19:57:36 +05:30
Arun Prakash Jana c248f42c31
Calculate number of cols for name only once 2017-09-01 19:30:25 +05:30
Arun Prakash Jana 7ec524c231
Change to light mode if < 35 columns are available 2017-09-01 18:58:32 +05:30
Arun Prakash Jana 2e3f013ce3
Remove redundant variable 2017-09-01 17:50:14 +05:30
Arun Prakash Jana dcc9b62760
Adjusting number of cols is redundant with shortening. 2017-09-01 10:45:10 +05:30
Arun Prakash Jana 1e5a0b8c5b
Fix #36: uneven splitting of codepoints
Check if the number of columns needed to print name exceeds the number of cols.
If it does, split the name str at the max number of columns available for name.
Conversion to wide char ensures the split is done at a valid codepoint.

The current patch adds some optimization as well:

- No more copying to an intermediate (global) string.
- If the name is shortened, escape chars are replaced only till the terminator.
2017-09-01 10:22:44 +05:30
Arun Prakash Jana c49b79d792
Fix cursor position issue with astral symbols
In case of astral symbols like Devanagari matras multiple wide-char codepoints
occupy a single position/column. Positioning the cursor wrt. the actual number
of wide-characters in a wide-char string gets "visually incorrect".  The trick
is to calculate the correct number of columns needed to represent a fixed-size
wide-character string.

Relevant man pages:

1. wcswidth(3)
2. wctomb(3)
3. mblen(3)

Interesting links:

1. https://www.gnu.org/software/libc/manual/html_node/Non_002dreentrant-Character-Conversion.html
2. https://www.gnu.org/software/libc/manual/html_node/Shift-State.html
3. https://10hash.com/c-programming/uchar/
4. https://mathiasbynens.be/notes/javascript-unicode#accounting-for-astral-symbols

Example file names for test:

1. Malgudi Days - मालगुडी डेज - E05. Swami and Friends - स्वामी और उसके दोस्त (Part 5)
2. Eso eso aamar ghare eso ♫ এসো এসো আমার ঘরে এসো ♫ Swagatalakshmi Dasgupta
3. Führer
2017-08-26 14:46:49 +05:30
Arun Prakash Jana ac03793547
A shorter overwrite message (key is not echoed) 2017-08-26 09:37:04 +05:30
Arun Prakash Jana 6b6182a61a Revert "Handle multi-byte: 2 codepoints single column"
This reverts commit e8cf0dc663.
2017-08-26 02:42:33 +05:30
Arun Prakash Jana e8cf0dc663
Handle multi-byte: 2 codepoints single column
Very frequent with Devanagari scripts ('matra's)
2017-08-26 02:35:01 +05:30
Arun Prakash Jana f94235333a
More concise help 2017-08-25 22:09:03 +05:30
Arun Prakash Jana 776d782fcf
Clear rename prompt with Ctrl-L 2017-08-25 21:49:55 +05:30
Arun Prakash Jana 4196af94f7
The '> ' as rename prompt is distracting 2017-08-25 19:22:30 +05:30
Arun Prakash Jana ccdb95f3ab
mbstowcs() returns the codepoints 2017-08-25 18:27:06 +05:30
Arun Prakash Jana b854f396cf Simplify filter handling 2017-08-25 14:13:26 +05:30
Arun Prakash Jana efc70f33e5
Get rid of getch() ('Führer' works now) 2017-08-25 13:57:22 +05:30
Arun Prakash Jana 76d582d5cd
Show line number only on fatal error 2017-08-24 22:26:46 +05:30
Arun Prakash Jana 512b7ac6cd
Re-order macros, globals... 2017-08-24 21:39:16 +05:30
Arun Prakash Jana f31978573e
Remove extern ref to wget_wch() 2017-08-24 19:43:11 +05:30
Arun Prakash Jana 05bb9db9e1
Remove extern ref to add_history() 2017-08-24 19:36:33 +05:30
Arun Prakash Jana 08b5fc8231
Fix build failure 2017-08-24 19:13:00 +05:30
Arun Prakash Jana 2f40eb5efc
Show volume capacity in help 2017-08-24 17:50:00 +05:30
Arun Prakash Jana 7275d68ab7
Rename MAX_BM to BM_MAX 2017-08-24 10:16:35 +05:30
Arun Prakash Jana 7c52e4a89e
Support multi-byte string in rename 2017-08-24 10:15:32 +05:30
Arun Prakash Jana f4b2e3a5df
Show filename in rename 2017-08-24 10:12:03 +05:30
Arun Prakash Jana e3bce10908
Add checks before dir access 2017-08-23 18:13:22 +05:30
Arun Prakash Jana f53f1b86e0
Remove shortcut F2 for refresh.
F2 is not very portable e.g., doesn't work over putty (default settings).
2017-08-23 17:36:32 +05:30
Arun Prakash Jana be337d883e
Disable dir watch in filter mode 2017-08-23 09:29:21 +05:30