|
4 | 4 | -- z.lua - a cd command that learns, by skywind 2018, 2019 |
5 | 5 | -- Licensed under MIT license. |
6 | 6 | -- |
7 | | --- Version 1.5.0, Last Modified: 2019/02/14 22:57 |
| 7 | +-- Version 1.5.1, Last Modified: 2019/02/15 11:26 |
8 | 8 | -- |
9 | 9 | -- * 10x faster than fasd and autojump, 3x faster than z.sh |
10 | 10 | -- * available for posix shells: bash, zsh, sh, ash, dash, busybox |
@@ -124,7 +124,6 @@ Z_SKIPPWD = false |
124 | 124 | os.LOG_NAME = os.getenv('_ZL_LOG_NAME') |
125 | 125 |
|
126 | 126 |
|
127 | | - |
128 | 127 | ----------------------------------------------------------------------- |
129 | 128 | -- string lib |
130 | 129 | ----------------------------------------------------------------------- |
@@ -779,8 +778,16 @@ function os.getopt(argv) |
779 | 778 | if head ~= '-' then |
780 | 779 | break |
781 | 780 | end |
782 | | - local part = arg:split('=') |
783 | | - options[part[1]] = part[2] ~= nil and part[2] or '' |
| 781 | + if arg == '-' then |
| 782 | + options['-'] = '' |
| 783 | + elseif arg == '--' then |
| 784 | + options['-'] = '-' |
| 785 | + elseif arg:match('^-%d+$') then |
| 786 | + options['-'] = arg:sub(2) |
| 787 | + else |
| 788 | + local part = arg:split('=') |
| 789 | + options[part[1]] = part[2] ~= nil and part[2] or '' |
| 790 | + end |
784 | 791 | end |
785 | 792 | index = index + 1 |
786 | 793 | end |
@@ -1540,16 +1547,28 @@ end |
1540 | 1547 |
|
1541 | 1548 |
|
1542 | 1549 | ----------------------------------------------------------------------- |
1543 | | --- cd forward |
1544 | | ------------------------------------------------------------------------ |
1545 | | -function cd_forward(args, options) |
1546 | | -end |
1547 | | - |
1548 | | - |
1549 | | ------------------------------------------------------------------------ |
1550 | | --- cd detour |
| 1550 | +-- cd minus: "z -", "z --", "z -2" |
1551 | 1551 | ----------------------------------------------------------------------- |
1552 | | -function cd_forward(args, options) |
| 1552 | +function cd_minus(args, options) |
| 1553 | + Z_SKIPPWD = true |
| 1554 | + local M = z_match({}, 'time', Z_SUBDIR) |
| 1555 | + local size = #M |
| 1556 | + if options['-'] == '-' then |
| 1557 | + for i, item in ipairs(M) do |
| 1558 | + if i > 10 then break end |
| 1559 | + io.stderr:write(' ' .. tostring(i - 1) .. ' ' .. item.name .. '\n') |
| 1560 | + end |
| 1561 | + else |
| 1562 | + local level = 0 |
| 1563 | + local num = options['-'] |
| 1564 | + if num and num ~= '' then |
| 1565 | + level = tonumber(num) |
| 1566 | + end |
| 1567 | + if level >= 0 and level < size then |
| 1568 | + return M[level + 1].name |
| 1569 | + end |
| 1570 | + end |
| 1571 | + return nil |
1553 | 1572 | end |
1554 | 1573 |
|
1555 | 1574 |
|
@@ -1588,10 +1607,8 @@ function main(argv) |
1588 | 1607 | local path = '' |
1589 | 1608 | if options['-b'] then |
1590 | 1609 | path = cd_backward(args, options) |
1591 | | - elseif options['-f'] then |
1592 | | - path = cd_forward(args, options) |
1593 | | - elseif options['-d'] then |
1594 | | - path = cd_detour(args, options) |
| 1610 | + elseif options['-'] then |
| 1611 | + path = cd_minus(args, options) |
1595 | 1612 | elseif #args == 0 then |
1596 | 1613 | path = nil |
1597 | 1614 | else |
@@ -2049,8 +2066,8 @@ function _zlua |
2049 | 2066 | else |
2050 | 2067 | _zlua_call "$_ZL_CD" "$dest" |
2051 | 2068 | end |
| 2069 | + if test -n "$_ZL_ECHO"; pwd; end |
2052 | 2070 | end |
2053 | | - if test -n "$_ZL_ECHO"; pwd; end |
2054 | 2071 | end |
2055 | 2072 | end |
2056 | 2073 |
|
|
0 commit comments