Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiler error on OS X 10.6 #1465

Closed
wants to merge 3,402 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
3402 commits
Select commit Hold shift + click to select a range
13f4a8c
Fix typo
krader1961 Aug 27, 2019
a724383
Move the `whence` documentation into a text file
krader1961 Aug 26, 2019
44fb5d5
Move the other builtin command docs into ext files
krader1961 Aug 26, 2019
f5ae4ee
Add comment explaining why `sh_set[]` isn't externalized
krader1961 Aug 26, 2019
a226181
Move libcmd into the ksh tree
krader1961 Aug 27, 2019
62fdca2
More builtin documention moved to external files
krader1961 Aug 26, 2019
282247d
Move more documentation out of the source code
krader1961 Aug 27, 2019
b0a1984
Lint cleanup
krader1961 Aug 28, 2019
e6e79c9
Remove deprecated cppcheck option
krader1961 Aug 28, 2019
da4f59d
cppcheck lint cleanup
krader1961 Aug 28, 2019
d0d07c6
Move b_command() into its own module
krader1961 Aug 28, 2019
2bf7a27
Refactor `export` and `readonly`
krader1961 Aug 28, 2019
3d3e417
Move b_alias() into its own module
krader1961 Aug 29, 2019
e3eb5e1
Move b_builtin() into its own module
krader1961 Aug 29, 2019
90f9b53
Move b_set() into its own module
krader1961 Aug 29, 2019
75f9c39
Move b_set() into its own module
krader1961 Aug 29, 2019
0b46d8c
Fix definition of `print_scan()` function
siteshwar Aug 29, 2019
15f781f
Make `print_scan()` function non-static
siteshwar Aug 29, 2019
13d6ace
Readd header needed on 32-bit platforms
krader1961 Aug 29, 2019
208c23d
Refactor bg_fg_disown.c
krader1961 Aug 29, 2019
7f1061c
Refactor module true_false.c
krader1961 Aug 29, 2019
6a372af
Refactor break_continue.c and return_exit.c
krader1961 Aug 29, 2019
5e0ff94
Refactor cd_pwd.c
krader1961 Aug 29, 2019
fb2e95b
Remove unsed, broken, "hash" builtin
krader1961 Aug 29, 2019
9ba9355
Enable code predicated on _c99_in_the_wild
krader1961 Aug 29, 2019
d5277d3
Refactor b_unset(), b_unalias, and unall()
krader1961 Aug 30, 2019
32d8131
Release ksh-2020.0.0-beta1
siteshwar Aug 30, 2019
0f44849
Remove dup `b_pwd()` leftover from previous refactoring
krader1961 Aug 30, 2019
36d688a
Move `sig_number()` out of trap.c
krader1961 Aug 30, 2019
990f237
Separate b_trap() and b_kill()
krader1961 Aug 30, 2019
e069b75
Eliminate pointless `Bltin()` preprocessor macro
krader1961 Aug 30, 2019
4de8a51
IWYU lint
krader1961 Aug 31, 2019
d89753b
Skip API test if build type != debug
krader1961 Sep 1, 2019
cb9f6d3
Ensure USER is set when unit tests run
krader1961 Sep 1, 2019
dc9fccc
Replace e_astbin with SH_CMDLIB_DIR
krader1961 Sep 2, 2019
a54c289
Introduce ${.sh.install_prefix}
krader1961 Sep 2, 2019
2d497fb
Make the code less fragile
krader1961 Sep 3, 2019
2bce63a
Switch to a more idiomatic end-of-table check
krader1961 Sep 3, 2019
657c587
Fix various typos found by codespell
hosiet Sep 3, 2019
a9d4bb0
Replace commit 2d497fbc with a better approach
krader1961 Sep 4, 2019
44463c0
Make b_times.exp unit test more robust
krader1961 Sep 6, 2019
24e968c
Convert `alias` documentation to Sphinx/RST
krader1961 Aug 31, 2019
fa9673c
Switch b_alias() from optget() to getopt_long()
krader1961 Sep 1, 2019
a08307c
Implement `man` function
krader1961 Sep 3, 2019
d0f92b4
Convert b_basename() to getopt_long()
krader1961 Sep 4, 2019
f4c1514
Changes to make the tests pass
krader1961 Sep 8, 2019
f124433
Cygwin source compatibility
krader1961 Sep 10, 2019
780492b
Lint: suggest parentheses around ‘&&’ within ‘||’
krader1961 Sep 11, 2019
3bd5b4f
Move b_echo() into its own module
krader1961 Sep 11, 2019
6153a5a
Fix shellcheck errors
krader1961 Sep 11, 2019
fca4d53
Switch b_bg() from optget() to getopt_long()
krader1961 Sep 11, 2019
0101139
Switch b_fg() from optget() to getopt_long()
krader1961 Sep 11, 2019
d49d8de
Switch b_break() from optget() to getopt_long()
krader1961 Sep 11, 2019
6d55cdc
Use `MESON_INSTALL_DESTDIR_PREFIX` variable
siteshwar Sep 11, 2019
9c9a5c8
[packaging] Add missing files in rpm builds
siteshwar Sep 11, 2019
244d9cc
[packaging] Fix rpm builds on opensuse
siteshwar Sep 11, 2019
ce77f93
Convert b_basename() to getopt_long()
krader1961 Sep 4, 2019
c085cbc
Introduce builtin_usage_error()
krader1961 Sep 12, 2019
d5d60da
Switch b_builtin() from optget() to getopt_long()
krader1961 Sep 11, 2019
c0abef8
Switch b_cat() from optget() to getopt_long()
krader1961 Sep 11, 2019
a2f9d59
Switch b_cd() from optget() to getopt_long()
krader1961 Sep 12, 2019
0f8af10
Switch b_chmod() from optget() to getopt_long()
krader1961 Sep 12, 2019
9487319
IWYU lint
krader1961 Sep 13, 2019
0ba0a7b
Switch b_cmp() from optget() to getopt_long()
krader1961 Sep 13, 2019
2102308
Switch b_command() from optget() to getopt_long()
krader1961 Sep 13, 2019
1687f3b
Switch to POSIXLY_CORRECT option parsing
krader1961 Sep 13, 2019
c4f582d
Fix expansion of bare tildes when HOME is unset
floppym Sep 5, 2019
6ef2ca5
make man
krader1961 Sep 13, 2019
7c174b5
Switch b_continue() from optget() to getopt_long()
krader1961 Sep 14, 2019
96b19ee
Correct which optget_long() error handling
krader1961 Sep 14, 2019
0f05131
Switch b_cut() from optget() to getopt_long()
krader1961 Sep 14, 2019
2b6e821
Don't assume `no_argument` is zero
krader1961 Sep 14, 2019
8aa6eea
Switch b_dirname() from optget() to getopt_long()
krader1961 Sep 14, 2019
b935f1a
Switch b_disown() from optget() to getopt_long()
krader1961 Sep 14, 2019
a421fe8
Switch b_source() from optget() to getopt_long()
krader1961 Sep 14, 2019
c682318
Document fix for issue #1391
krader1961 Sep 14, 2019
c44e124
Use sphinx to generate the docs if available
krader1961 Sep 14, 2019
bc155a2
Create echo.rst document
krader1961 Sep 15, 2019
c3a2b14
Switch b_enum() from optget() to getopt_long()
krader1961 Sep 15, 2019
62fd830
Man page rst cleanups
krader1961 Sep 15, 2019
9484249
Commit more Sphinx build artifacts
krader1961 Sep 15, 2019
d9491d4
Fix regression involving `command` builtin
krader1961 Sep 15, 2019
8aa9ac9
Switch b_eval() from optget() to getopt_long()
krader1961 Sep 15, 2019
1da542f
Switch b_exec() from optget() to getopt_long()
krader1961 Sep 15, 2019
e0c4882
Switch b_exit() from optget() to getopt_long()
krader1961 Sep 16, 2019
57085ad
Switch b_export() from optget() to getopt_long()
krader1961 Sep 16, 2019
c584641
Switch b_head() from optget() to getopt_long()
krader1961 Sep 16, 2019
695269a
Switch b_hist() from optget() to getopt_long()
krader1961 Sep 16, 2019
66d0976
Commit more Sphinx build artifacts
krader1961 Sep 16, 2019
1c9e7ab
Revert "Switch b_hist() from optget() to getopt_long()"
krader1961 Sep 17, 2019
91a75b9
Normalize sentinel value of a Shtable_t[]
krader1961 Sep 17, 2019
1eb928a
run_test.sh: exit with status 77 when skipping a test
floppym Sep 17, 2019
25f73f4
Initialize the jobs table earlier
krader1961 Sep 18, 2019
1893891
Switch b_hist() from optget() to getopt_long()
krader1961 Sep 19, 2019
4c9c596
Fix and normalize handling of atypical CLI flags
krader1961 Sep 19, 2019
98bc42a
Make unit test compatible with Cygwin
krader1961 Sep 19, 2019
3dffc9d
Switch b_jobs() from optget() to getopt_long()
krader1961 Sep 20, 2019
abe5bd6
Switch b_kill() from optget() to getopt_long()
krader1961 Sep 20, 2019
957ce01
Fix `exit` getopt_long() short options
krader1961 Sep 20, 2019
376b085
Fix `head` handling of integer flags
krader1961 Sep 20, 2019
abf06c2
Remove support for negative ints from `bg` and `fg`
krader1961 Sep 20, 2019
7368706
Man page style improvements
krader1961 Sep 20, 2019
c3aa2d5
Switch b_let() from optget() to getopt_long()
krader1961 Sep 20, 2019
46215d4
Switch b_logname() from optget() to getopt_long()
krader1961 Sep 21, 2019
eb8e227
Switch b_mkdir() from optget() to getopt_long()
krader1961 Sep 21, 2019
0ffecb0
man: Silence mandoc warnings in ksh.1.
orbea Sep 21, 2019
7c17e44
bin/style all
krader1961 Sep 21, 2019
7b5953c
eliminate some unused preprocessor symbols
krader1961 Sep 21, 2019
f4d7c1b
Add more `print -R` tests
krader1961 Sep 22, 2019
6993358
Refactor b_print(), b_echo(), and b_printf()
krader1961 Sep 22, 2019
08ab0ec
Remove `login` and `newgrp` special builtins
krader1961 Sep 24, 2019
1885d04
Switch b_print() from optget() to getopt_long()
krader1961 Sep 24, 2019
72e1624
Switch b_printf() from optget() to getopt_long()
krader1961 Sep 25, 2019
7f06b58
Switch b_pwd() from optget() to getopt_long()
krader1961 Sep 25, 2019
4e401a9
Switch b_read() from optget() to getopt_long()
krader1961 Sep 25, 2019
4f00fdb
Switch b_readonly() from optget() to getopt_long()
krader1961 Sep 25, 2019
8bdfa5b
Switch b_return() from optget() to getopt_long()
krader1961 Sep 25, 2019
857b058
Change naming of ksh script based tests
krader1961 Sep 25, 2019
1b34915
Fix regression involving invalid char class name
krader1961 Sep 27, 2019
2828fd9
Eliminate Meson warning about our config file
krader1961 Sep 28, 2019
07e8829
Coverity Scan lint cleanup
krader1961 Sep 29, 2019
8031fed
Remove pointless checks of malloc() failing
krader1961 Sep 29, 2019
762f838
Switch shcomp from optget() to getopt_long()
krader1961 Sep 30, 2019
ce7e096
Switch b_shift() from optget() to getopt_long()
krader1961 Sep 30, 2019
3be7e10
Switch b_sleep() from optget() to getopt_long()
krader1961 Sep 30, 2019
461707e
Switch b_sync() from optget() to getopt_long()
krader1961 Oct 1, 2019
cfec3cb
Switch b_test() from optget() to getopt_long()
krader1961 Oct 1, 2019
5c3052b
Switch b_times() from optget() to getopt_long()
krader1961 Oct 1, 2019
394ba62
Switch b_trap() from optget() to getopt_long()
krader1961 Oct 1, 2019
39bf126
Switch b_ulimit() from optget() to getopt_long()
krader1961 Oct 1, 2019
541a7d4
Switch b_umask() from optget() to getopt_long()
krader1961 Oct 2, 2019
3955a1c
Switch b_unalias() from optget() to getopt_long()
krader1961 Oct 2, 2019
485fb82
bin/style all
krader1961 Oct 2, 2019
fcd6535
Lint cleanup
krader1961 Oct 2, 2019
31aec52
Switch b_uname() from optget() to getopt_long()
krader1961 Oct 2, 2019
f8a6aa6
Switch b_unset() from optget() to getopt_long()
krader1961 Oct 2, 2019
28592fc
Switch b_wait() from optget() to getopt_long()
krader1961 Oct 3, 2019
44d6381
Switch b_wc() from optget() to getopt_long()
krader1961 Oct 3, 2019
c68faf0
Switch b_whence() from optget() to getopt_long()
krader1961 Oct 3, 2019
e02c662
Simplify nv_addtype()
krader1961 Oct 3, 2019
45ea282
Remove the `type` builtin
krader1961 Oct 3, 2019
669656b
Switch b_complete() from optget() to getopt_long()
krader1961 Oct 4, 2019
e30225b
make man
krader1961 Oct 4, 2019
7005717
Enable the expect based tests on FreeBSD
krader1961 Oct 4, 2019
2095983
Fix `complete` flag handling
krader1961 Oct 5, 2019
c3098f7
Improve handling of unit test timeouts
krader1961 Oct 6, 2019
c52d3a3
Enable real-time signal test
krader1961 Oct 7, 2019
b18d4ae
Fix meson status of skipped shcomp tests
krader1961 Oct 9, 2019
a5ecd1c
Cleanup feature test artifacts
krader1961 Oct 10, 2019
ad9d63d
Show version number through `ksh --version`
siteshwar Oct 9, 2019
f5d2e83
Update changelog with stable version number
siteshwar Oct 9, 2019
d2e31cc
Move the logic for skipping tests
krader1961 Oct 9, 2019
d1de147
Minor spelling fixes
aweeraman Oct 19, 2019
ddfe6b3
Implement an optget() like alternative
krader1961 Oct 14, 2019
7faa294
Switch from getopt_long() to optget_long()
krader1961 Oct 19, 2019
a9b86b6
Convert some getopt_long_only() to optget_long()
krader1961 Oct 19, 2019
84648ca
Convert remaining getopt_long_only()
krader1961 Oct 21, 2019
856f994
Add more optget_long() unit tests
krader1961 Oct 25, 2019
e7713a5
Try to reduce false positive expect test failures
krader1961 Oct 27, 2019
2df35bd
style --all
krader1961 Oct 28, 2019
c791a0d
Silence Coverity Scan lint warning
krader1961 Oct 28, 2019
7f5e094
Silence some bogus IWYU compiler warnings
krader1961 Oct 28, 2019
bd87dbf
Remove irrelevant assignment
krader1961 Oct 28, 2019
0d96c25
Silence lint warning about uninitialized var
krader1961 Oct 28, 2019
8e019ec
Silence lint: "Null pointer dereference"
krader1961 Oct 28, 2019
0451612
cppcheck lint elimination
krader1961 Oct 28, 2019
fec0369
silence cppcheck lint warnings
krader1961 Oct 28, 2019
a32b02c
silence cppcheck lint warnings
krader1961 Oct 28, 2019
d9103c8
Remove a couple of no longer needed cppcheck suppressions
krader1961 Oct 28, 2019
dd2c8ea
Make `DPRINTF()` more robust
krader1961 Oct 29, 2019
4a5d206
Use `static_fn` rather than `static`
krader1961 Oct 29, 2019
4503830
Update Travis "fedora" config
krader1961 Oct 29, 2019
9490d10
Correct invalid argv[-1]
krader1961 Oct 30, 2019
6511635
Silence cppcheck warning about argv[-1]
krader1961 Oct 30, 2019
651e614
Fix `cd` function and make it automatically available
krader1961 Oct 26, 2019
286203f
Run autoloaded functions through shellcheck
krader1961 Oct 30, 2019
886d86f
Fix errors due to wchar_t being two bytes
krader1961 Oct 31, 2019
f867740
Adapt unit test to new Travis Fedora env
krader1961 Oct 31, 2019
c6c8c0c
Eliminate some pointless log file content
krader1961 Nov 1, 2019
42e8a04
Eliminate command help on error if not interactive
krader1961 Nov 1, 2019
1a34ebd
lower test parallelism on travis macos
krader1961 Nov 2, 2019
2580181
enable malloc debug on travis macos
krader1961 Nov 2, 2019
b058d8c
Fix b_sync.sh test failures on some macOS systems
krader1961 Nov 2, 2019
11983a7
Fix fallback addrs2info()
danyspin97 Nov 2, 2019
8e4c8f0
Fix for test failures when home directory is not available
aweeraman Nov 3, 2019
4a438e5
Move the generated version from a .h to a .c file
krader1961 Nov 5, 2019
91b3806
Revert "Move the generated version from a .h to a .c file"
krader1961 Nov 7, 2019
a205e5a
Tweak to the -s argument and the log message to match
aweeraman Nov 3, 2019
a3c2dfb
Fix hist_nearend()
krader1961 Nov 8, 2019
c584768
Lint cleanup
krader1961 Nov 8, 2019
c25958e
Remove unused header siglist.h
krader1961 Nov 8, 2019
ffbfaf6
"unknown flag" -> "unknown option"
krader1961 Nov 8, 2019
a0c44c9
Fix ed_expand()
krader1961 Nov 10, 2019
7df11de
`functions` with not loaded autoloaded functions
krader1961 Nov 13, 2019
7c92227
Regression tests for `typeset -f` fix
krader1961 Nov 15, 2019
d72c3a6
Move the generated version from a .h to a .c file
krader1961 Nov 15, 2019
c99e9ff
Improve style of sh_close()
krader1961 Nov 15, 2019
359bf21
Add instructions for installing with MacPorts
ryandesign Nov 16, 2019
0525de9
Disable flakey API unit test
krader1961 Nov 17, 2019
42a580c
Add comment regarding the need to keep "Version A"
krader1961 Nov 20, 2019
c1af9c6
Add missing optional header
krader1961 Nov 29, 2019
61cfd45
Cleanup: remove unused function
krader1961 Nov 29, 2019
9c7211b
Improve meson warning message wording
krader1961 Nov 29, 2019
2806b21
Lint: Dangerous assignment
krader1961 Dec 1, 2019
5c16e8d
Lint cleanup
krader1961 Dec 1, 2019
ca8c7e6
Remove description of case modification operator
siteshwar Dec 9, 2019
fbaf00e
Lint: negativeIndex
krader1961 Dec 2, 2019
f05b619
Lint: invalidPointerCast
krader1961 Dec 2, 2019
82d4f30
Use the ksh semantic version in docs
krader1961 Dec 15, 2019
6928edc
Fix bug introduced by commit 6542e5a3
krader1961 Dec 5, 2019
d0a7db5
Fix shellcheck warnings created by previous commit
krader1961 Dec 15, 2019
bc901af
Enable shellcheck of standard ksh functions
krader1961 Dec 16, 2019
02525a3
Enable shellcheck on more shell scripts
krader1961 Dec 16, 2019
5efb243
Fix shellcheck errors
krader1961 Dec 16, 2019
c7de8b6
Harden env var imports
krader1961 Dec 13, 2019
c007254
Fix unit test build on NetBSD
krader1961 Dec 19, 2019
c6757a2
Fix unit test build on NetBSD
krader1961 Dec 20, 2019
b6be7e7
Harden unit test against slow test environments
krader1961 Dec 20, 2019
0d76ee4
Add option to disable */shcomp test variants
krader1961 Dec 22, 2019
2950ede
Deal with PATH being unset when running unit tests
krader1961 Dec 26, 2019
74c34dc
Move empty PATH workaround into global config
krader1961 Dec 28, 2019
d9ecc21
Fix a unit test that assumes FPATH is unset
krader1961 Dec 28, 2019
37cb9ea
Harden the test runner against a bad $PATH
krader1961 Dec 29, 2019
db20aab
Update for compatibility with macOS on TravisCI
krader1961 Dec 29, 2019
5abcbd0
Eliminate $NO_SHCOMP env var
krader1961 Dec 29, 2019
3bc5816
Fix handling of skipped directories
krader1961 Jan 9, 2020
80cc081
Avoid false positive failures of b_time.exp
krader1961 Jan 10, 2020
031d73a
Fix b_printf.sh unit test on Cygwin
krader1961 Jan 10, 2020
078cb99
Clarify how to run unit tests
krader1961 Jan 11, 2020
55cad1d
Fix potential fd leak
krader1961 Jan 12, 2020
2f9b39e
Fix b_print.sh unit test on Cygwin
krader1961 Jan 12, 2020
6b6146e
Simplify invalid locale testing
krader1961 Jan 13, 2020
b29a24d
Print correct version string on `ksh --version`
krader1961 Jan 15, 2020
b277665
Eliminate unneeded use of `getconf`
krader1961 Jan 15, 2020
2f06a34
Eliminate bogus locale tests
krader1961 Jan 15, 2020
127d2e4
Remove another `getconf LIBPATH`
krader1961 Jan 16, 2020
0641d89
Remove another bogus getconf use
krader1961 Jan 16, 2020
f80d386
Move `cd` command so `cd ~-` works
krader1961 Jan 16, 2020
d5f4cb6
Remove the remaining bogus `getconf` mention
krader1961 Jan 17, 2020
9fa5b47
Remove unused e_crondir var
krader1961 Jan 20, 2020
2986f8b
Integrate nv_optimize() bug fix from OpenSuse
krader1961 Jan 20, 2020
46d4981
Replace `0` with `NULL` to clarify intent
krader1961 Jan 20, 2020
1fd82bd
Fix interactive restricted shell behavior
krader1961 Jan 22, 2020
459a380
Eliminate pointless external getconf use
krader1961 Jan 24, 2020
3dfc236
Fix cd function and enable it in unit tests
krader1961 Nov 26, 2019
5000e7f
Rename three vars associated with cd related funcs
krader1961 Jan 26, 2020
43d1853
Suppress false-positive shellcheck warnings
krader1961 Jan 26, 2020
db54d36
Change default build type to "minsize"
krader1961 Jan 27, 2020
8cf92b2
Fix typo in the project name
krader1961 Feb 1, 2020
f8290d2
Fix compiler error on OS X 10.6
krader1961 Feb 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix cd function and make it automatically available
User Andras Farkas <[email protected]> brought this issue to our
attention via a message on the ksh mailing list. There are two problems.
First, autoloaded functions `cd` and `mcd` aren't available until the
user uses the `dirs` command. So put each function definition in its own
autoloaded file. Second, the `_cd` function behaves incorrectly if you
invoke it with no arguments.

I'm ambivalent about the `_cd` behavior of always printing the selected
directory on stdout. Personally I think that is just noise. If the user
wants to be reminded what the CWD is they can put it in their prompt.
But I'm keeping that behavior for the moment to see how others feel and
because that is what the legacy implementation does which implies some
people think the behavior is useful.
krader1961 committed Oct 30, 2019
commit 651e6148006a0fc48638ffed26791d8ce13b1010
16 changes: 16 additions & 0 deletions src/cmd/ksh93/data/config.ksh
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@
# shell state. For example, where to find autoloaded functions that ship with the shell and arrange
# for them to be loaded on demand. It should not do anything not suitable for every single new ksh
# process. In particular it should be as fast as possible.
#

#
# Arrange for standard autoloaded functions to be available. The test for whether or not FPATH is
# already set isn't technically necessary since empty path components are guaranteed not to be
@@ -21,4 +23,18 @@ for f in "$__fpath"/*
do
typeset -fu $(basename $f)
done

# Global vars for the `_cd`, `mcd`, `pushd`, `popd`, `dirs` functions.
integer _push_max=${CDSTACK:-32}
integer _push_top=${CDSTACK:-32}
typeset -a _push_stack

# Prefer the `cd` function to the `cd` builtin as the function is needed for functions like
# `dirs` and `popd` to work. Only do this for interactive shells.
if [[ $- == *i* && -f "$__fpath/_cd" ]]
then
unalias cd 2>/dev/null # the alias probably doesn't exist so don't complain in that case
alias cd=_cd
fi

unset __fpath
87 changes: 87 additions & 0 deletions src/cmd/ksh93/functions/_cd
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Change directory and push the directory on the dir stack. This also recognizes some extensions su
# has `cd -2` to cd to the second most recently visited directory.
function _cd {
typeset dir=''
integer n=0
integer type=4

case $1 in
-|-1|2) # \cd -
n=_push_top
type=1
;;
-[1-9]*([0-9])) # \cd -n
n=_push_top+${1#-}-1
type=2
;;
1) # keep present directory
print -r - "$PWD"
return
;;
[1-9]*([0-9])) # \cd n
n=_push_top+${1}-2
type=2
;;
*)
if (( _push_top <= 0 ))
then
n=_push_max
type=3
fi
;;
esac

if (( type < 3 ))
then
if (( n >= _push_max + 1 ))
then
print -u2 cd: Directory stack not that deep.
return 1
else
dir="${_push_stack[n]}"
fi
fi

case $dir in
\~*) dir=$HOME${dir#\~}
esac

(( $# == 0 )) && set -- ~/
\cd "${dir:-$@}" || return 1

dir="${OLDPWD#$HOME/}"

# TODO: Generalize this so it works on every terminal that supports setting its title string.
case $TERM in
630)
print "\033[?${#PWD};2v$PWD\c"
;;
esac

case "$dir" in
$HOME)
dir="~"
;;
/*) ;;
*) dir="~/$dir"
;;
esac

case "$type" in
1) # swap first two elements
_push_stack[_push_top]="$dir"
;;
2|3) # put $dir on top and shift down by one until top
integer i=_push_top
for dir in "$dir" "${_push_stack[@]}"
do (( i > n )) && break
_push_stack[i]="$dir"
(( i = i + 1 ))
done
;;
4) # push name
_push_stack[_push_top=_push_top - 1]="$dir"
;;
esac
print -r - "$PWD"
}
108 changes: 10 additions & 98 deletions src/cmd/ksh93/functions/dirs
Original file line number Diff line number Diff line change
@@ -1,108 +1,20 @@
#
# DIRECTORY MANIPULATION FUNCTIONS, REPLACES CD
#
# Uses global parameters _push_max _push_top _push_stack
integer _push_max=${CDSTACK-32} _push_top=${CDSTACK-32}
unalias cd
alias cd=_cd
# Display directory stack -- $HOME displayed as ~
function dirs
{
# Display directory stack -- $HOME displayed as ~.
function dirs {
typeset dir="${PWD#$HOME/}"
case $dir in
$HOME)
dir=\~
;;
/*) ;;
*) dir=\~/$dir
esac
PS3=
select i in "$dir" "${_push_stack[@]}"
do :
done < /dev/null
}

# Change directory and put directory on front of stack
function _cd
{
typeset dir=
integer n=0 type=4
case $1 in
-|-1|2) # \cd -
n=_push_top type=1
;;
-[1-9]*([0-9])) # \cd -n
n=_push_top+${1#-}-1 type=2
;;
1) # keep present directory
print -r - "$PWD"
return
;;
[1-9]*([0-9])) # \cd n
n=_push_top+${1}-2 type=2
/*)
;;
*) if ((_push_top <= 0))
then type=3 n=_push_max
fi
esac
if ((type<3))
then if ((n >= _push_max+1))
then print -u2 cd: Directory stack not that deep.
return 1
else dir=${_push_stack[n]}
fi
fi
case $dir in
\~*) dir=$HOME${dir#\~}
esac
\cd "${dir:-$@}" >| /dev/null || return 1
dir=${OLDPWD#$HOME/}
case $TERM in
630)
print "\033[?${#PWD};2v$PWD\c"
;;
esac
case $dir in
$HOME)
dir=\~
*)
dir=\~/$dir
;;
/*) ;;
*) dir=\~/$dir
esac
case $type in
1) # swap first two elements
_push_stack[_push_top]=$dir
;;
2|3) # put $dir on top and shift down by one until top
integer i=_push_top
for dir in "$dir" "${_push_stack[@]}"
do ((i > n)) && break
_push_stack[i]=$dir
i=i+1
done
;;
4) # push name
_push_stack[_push_top=_push_top-1]=$dir
;;
esac
print -r - "$PWD"
}

# Menu driven change directory command
function mcd
{
typeset dir="${PWD#$HOME/}"
case $dir in
$HOME)
dir=\~
;;
/*) ;;
*) dir=\~/$dir
esac
PS3='Select by number or enter a name: '
select dir in "$dir" "${_push_stack[@]}"
do if _cd $REPLY
then return
fi
done
PS3=''
select i in "$dir" "${_push_stack[@]}"
do
:
done < /dev/null
}
20 changes: 20 additions & 0 deletions src/cmd/ksh93/functions/mcd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Menu driven change directory command.
function mcd {
typeset dir="${PWD#$HOME/}"
case $dir in
$HOME) dir=\~
;;
/*) ;;
*) dir=\~/$dir
;;
esac

PS3='Select by number or enter a name: '
select dir in "$dir" "${_push_stack[@]}"
do
if _cd $REPLY
then
return
fi
done
}
23 changes: 15 additions & 8 deletions src/cmd/ksh93/tests/attributes.sh
Original file line number Diff line number Diff line change
@@ -511,14 +511,21 @@ expected='typeset -a x=(a\=3 b\=4)'
typeset -a x=( a=3 b=4)
[[ $(typeset -p x) == "$expected" ]] || log_error 'assignment elements in typeset -a assignment not working'

unset z
z='typeset -a q=(a b c)'
$SHELL -c "$z; [[ \$(typeset -pa) == '$z' ]]" || log_error 'typeset -pa does not list only index arrays'
z='typeset -C z=(foo=bar)'
$SHELL -c "$z; [[ \$(typeset -pC) == '$z' ]]" || log_error 'typeset -pC does not list only compound variables'
unset y
z='typeset -A y=([a]=foo)'
$SHELL -c "$z; [[ \$(typeset -pA) == '$z' ]]" || log_error 'typeset -pA does not list only associative arrays'
# We need to unset `push_stack` because it is defined automatically in each shell instance.
expect='typeset -a q=(a b c)'
actual=$($SHELL -c "$expect; unset _push_stack; typeset -pa")
[[ "$expect" == "$actual" ]] ||
log_error 'typeset -pa does not list only index arrays' "$expect" "$actual"

expect='typeset -C z=(foo=bar)'
actual=$($SHELL -c "$expect; typeset -pC")
[[ "$expect" == "$actual" ]] ||
log_error 'typeset -pC does not list only compound variables' "$expect" "$actual"

expect='typeset -A y=([a]=foo)'
actual=$($SHELL -c "$expect; typeset -pA");
[[ "$expect" == "$actual" ]] ||
log_error 'typeset -pA does not list only associative arrays' "$expect" "$actual"

$SHELL -c 'typeset -C arr=( aa bb cc dd )' &&
log_error 'invalid compound variable assignment not reported'