Path: csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Martijn Dekker Newsgroups: gnu.bash.bug Subject: [PATCH] fc: trim range instead of erroring out Date: Tue, 11 Aug 2020 16:59:57 +0100 Lines: 74 Approved: bug-bash@gnu.org Message-ID: References: NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------3DCC80151DA6249570A46CA7" X-Trace: usenet.stanford.edu 1597161607 14743 209.51.188.17 (11 Aug 2020 16:00:07 GMT) X-Complaints-To: action@cs.stanford.edu To: Bug reports for the GNU Bourne Again SHell Envelope-to: bug-bash@gnu.org User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 Content-Language: en-GB Received-SPF: none client-ip=2a02:2770::21a:4aff:fec6:e3d8; envelope-from=martijn@inlv.org; helo=freekahlil.inlv.org X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, MAY_BE_FORGED=1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, URIBL_BLOCKED=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: Xref: csiph.com gnu.bash.bug:16741 This is a multi-part message in MIME format. --------------3DCC80151DA6249570A46CA7 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit As I use/try/test many shells, I'm in the habit of using POSIX commands such as 'fc -l 1' to list the complete history. If there have been more than $HISTSIZE command, the list is trimmed at the beginning without renumbering, and bash errors out: $ fc -l 1 bash-5.0: fc: history specification out of range This is different from every other shell, and also looks like it's contrary to the POSIX spec: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/fc.html#tag_20_44_05 | When a range of commands is used, it shall not be an error to specify | first or last values that are not in the history list; fc shall | substitute the value representing the oldest or newest command in the | list, as appropriate. For example, if there are only ten commands in | the history list, numbered 1 to 10: | | fc -l | fc 1 99 | | shall list and edit, respectively, all ten commands. The attached patch removes the error and limits the range to available commands as specified. - Martijn -- || modernish -- harness the shell || https://github.com/modernish/modernish || || KornShell lives! || https://github.com/ksh93/ksh --------------3DCC80151DA6249570A46CA7 Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="fc.patch" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="fc.patch" ZGlmZiAtLWdpdCBhL2J1aWx0aW5zL2ZjLmRlZiBiL2J1aWx0aW5zL2ZjLmRlZgppbmRleCBj MjY2YWMyYy4uN2Y2MDZjNTIgMTAwNjQ0Ci0tLSBhL2J1aWx0aW5zL2ZjLmRlZgorKysgYi9i dWlsdGlucy9mYy5kZWYKQEAgLTMyMSwxMCArMzIxLDcgQEAgZmNfYnVpbHRpbiAobGlzdCkK ICAgICB3aGlsZSAobGFzdF9oaXN0ID49IDAgJiYgaGxpc3RbbGFzdF9oaXN0XSA9PSAwKQog ICAgICAgbGFzdF9oaXN0LS07CiAgIGlmIChsYXN0X2hpc3QgPCAwKQotICAgIHsKLSAgICAg IHNoX2VyYW5nZSAoKGNoYXIgKilOVUxMLCBfKCJoaXN0b3J5IHNwZWNpZmljYXRpb24iKSk7 Ci0gICAgICByZXR1cm4gKEVYRUNVVElPTl9GQUlMVVJFKTsKLSAgICB9CisgICAgbGFzdF9o aXN0ID0gMDsKIAogICBpZiAobGlzdCkKICAgICB7CkBAIC0zNTMsMTIgKzM1MCwxMCBAQCBm Y19idWlsdGluIChsaXN0KQogCWhpc3RiZWcgPSBoaXN0ZW5kID0gbGFzdF9oaXN0OwogICAg IH0KIAotICAvKiBXZSBwcmludCBlcnJvciBtZXNzYWdlcyBmb3IgbGluZSBzcGVjaWZpY2F0 aW9ucyBvdXQgb2YgcmFuZ2UuICovCi0gIGlmICgoaGlzdGJlZyA8IDApIHx8IChoaXN0ZW5k IDwgMCkpCi0gICAgewotICAgICAgc2hfZXJhbmdlICgoY2hhciAqKU5VTEwsIF8oImhpc3Rv cnkgc3BlY2lmaWNhdGlvbiIpKTsKLSAgICAgIHJldHVybiAoRVhFQ1VUSU9OX0ZBSUxVUkUp OwotICAgIH0KKyAgaWYgKGhpc3RiZWcgPCAwKQorICAgIGhpc3RiZWcgPSAwOworICBpZiAo aGlzdGVuZCA8IDApCisgICAgaGlzdGVuZCA9IDA7CiAKICAgLyogIldoZW4gbm90IGxpc3Rp bmcsIHRoZSBmYyBjb21tYW5kIHRoYXQgY2F1c2VkIHRoZSBlZGl0aW5nIHNoYWxsIG5vdCBi ZQogICAgICBlbnRlcmVkIGludG8gdGhlIGhpc3RvcnkgbGlzdC4iICovCkBAIC0zODIsMTIg KzM3NywxMCBAQCBmY19idWlsdGluIChsaXN0KQogCWhpc3RiZWcgPSBsYXN0X2hpc3Q7CiAg ICAgfQogCi0gIC8qIFdlIHByaW50IGVycm9yIG1lc3NhZ2VzIGZvciBsaW5lIHNwZWNpZmlj YXRpb25zIG91dCBvZiByYW5nZS4gKi8KLSAgaWYgKChoaXN0YmVnIDwgMCkgfHwgKGhpc3Rl bmQgPCAwKSkKLSAgICB7Ci0gICAgICBzaF9lcmFuZ2UgKChjaGFyICopTlVMTCwgXygiaGlz dG9yeSBzcGVjaWZpY2F0aW9uIikpOwotICAgICAgcmV0dXJuIChFWEVDVVRJT05fRkFJTFVS RSk7Ci0gICAgfQorICBpZiAoaGlzdGJlZyA8IDApCisgICAgaGlzdGJlZyA9IDA7CisgIGlm IChoaXN0ZW5kIDwgMCkKKyAgICBoaXN0ZW5kID0gMDsKIAogICBpZiAoaGlzdGVuZCA8IGhp c3RiZWcpCiAgICAgewo= --------------3DCC80151DA6249570A46CA7--