Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 6 Sep 2012 21:21:58 +0200
From: Frank Dittrich <frank_dittrich@...mail.com>
To: john-dev@...ts.openwall.com
Subject: Re: bash completion on OSX

On 09/06/2012 09:35 AM, magnum wrote:
> On 6 Sep, 2012, at 7:50 , Frank Dittrich <frank_dittrich@...mail.com> wrote:
>> Can you test if bash's syntax check complains about
>> --restore|--status)
>> as well (if you comment out or delete the
>> -?(-)f?(o|or|orm|orma|ormat)+(=|:)*)
>> and subsequent lines?
> 
> bash: _get_comp_words_by_ref: command not found

_get_comp_words_by_ref should be defined in /etc/bash_completion.
Since this error disappeared when you installed bash completion for git,
I'll currently not spend time investigating this problem any further.

> sed: 1: "{ s#^ *\(--[a-z-]*=\?\( ...": bad flag in substitute command: '}'
> 
> This error is run-time (happens when I press TAB). Actually, I now enabled git completion which apparently in turn enables globbing. After that, sourcing the pristine john completion file works fine, but I now get a similar run-time error:
> 
> bash-4.2$ ../run/john[TAB] sed: 1: "{ s#^ *\(--[a-z-]*=\?\( ...": bad flag in substitute command: '}'


Google apparently provided the answer:
"OS X sed doesn't like multiple commands run together using semicolons
or grouped in curly braces"
and
"If you have a sed script that consists of multiple commands, you'll
have to break them up using -e"

I have two sed commands in the bash completion script which use '{'.
One in line 139, one in line 183.
Even if I s/sed -n/sed --posix -n/ in both of these lines, bash
completion still works for me.

If OSX has a problem here, that suggests the sed command  implementaion
used for OSX is not POSIX compatible, or GNU sed has a bug (not
disabling all GNU extensions when using sed --posix).

For the first of the two sed commands mentioned above, I can easily get
rid of { and }.

To get rid of the ';', I had to split the sed scripts into several
scripts per command.

I tested my changes with and without defining
alias sed='sed --posix'

So the attached patch should work. (I also improved the grammar of the
comment regarding extended pattern matching.)
I tested it on top of

commit 745a66151edffb9e6f745d6a6cc1546ae2e236ed
Author: magnum <john.magnum@...hmail.com>
Date:   Wed Aug 22 07:30:29 2012 +0200

    RAR: fix a compiler warning on 32-bit

This is the latest 1.7.9-jumbo-6-fixes commit I have on my 32bit linux
netbook, but I guess bash completion hasn't much changed since then.


Because I didn't intend to do any john related work while on vacation,
my public git repo is also way behind the official repo, and I don't
want to spend more time on this than necessary.
That's why, currently, I don't want to send a pull request.

Please test and apply the attached patch if it works for you as well.

Frank

>From 4168598ab99ff8a01d0f4cac4baa385e1299b0ea Mon Sep 17 00:00:00 2001
From: Frank Dittrich <frank_dittrich@...mail.com>
Date: Thu, 6 Sep 2012 21:04:39 +0200
Subject: [PATCH] Make bash completion work for OS X

---
 run/john.bash_completion |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/run/john.bash_completion b/run/john.bash_completion
index 6959cb6..59d666e 100644
--- a/run/john.bash_completion
+++ b/run/john.bash_completion
@@ -14,7 +14,7 @@
 # 	shopt -p extglob
 # prints
 #	shopt -s extglob
-# then the extended pattern matching features enabled. If this command
+# then the extended pattern matching features are enabled. If this command
 # prints
 # 	shopt -u extglob
 # then they are disabled.
@@ -136,7 +136,7 @@ _john()
 #	All options (the '=' will be removed for options with an optional value)
 	options=""
 # FIXME: How do I suppress the error message if someone tries to be clever: cd run; ./john --[tab] ???
-	options="`${first} 2>/dev/null|sed -n '{ s#^ *\(--[a-z-]*=\?\(LIST\)\?\).*$#\1# }; /^--/ p'` --stdin"
+	options="`${first} 2>/dev/null|sed -n -e 's#^ *\(--[a-z-]*=\?\(LIST\)\?\).*$#\1#' -e '/^--/ p'` --stdin"
 	if [[ "_${options}" == "_ --stdin" ]] ; then
 		_filedir_xspec 2> /dev/null
 		return 0
@@ -180,7 +180,7 @@ _john()
 				fi
 			fi
 			cur=`echo ${cur#*[=:]}|LC_ALL=C tr A-Z a-z`
-			formats=`${first} |sed -n '/^--format/,$ { s#^--format=[ A-Za-z]*:##; /^--/ b; s#^ *##; s#\<dynamic_n\>#dynamic#; s#^\(.*\)$#\L\1#; s#[/ ]#\n#g; p }'`
+			formats=`${first} |sed -n -e '/^--format/,$ {' -e 's#^--format=[ A-Za-z]*:##' -e '/^--/ b' -e 's#^ *##' -e 's#\<dynamic_n\>#dynamic#' -e 's#^\(.*\)$#\L\1#' -e 's#[/ ]#\n#g' -e 'p }'`
 			COMPREPLY=( $(compgen -W "${formats}" -- ${cur}) )
 			if [[ "${COMPREPLY[0]}_" == dynamic_ ]] ; then
 				compopt -o nospace
-- 
1.7.7.6


Powered by blists - more mailing lists

Your e-mail address:

Powered by Openwall GNU/*/Linux - Powered by OpenVZ