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

counsel-find-file-occur doesn't seem to work on macOS #1299

Closed
aaronjensen opened this Issue Nov 21, 2017 · 21 comments

Comments

Projects
None yet
4 participants
@aaronjensen
Contributor

aaronjensen commented Nov 21, 2017

When using counsel-find-file-occur, I don't get any results when using ivy--regex-fuzzy.

If I search for just o, it attempts to run:

ls | grep -i -E '\(o\)' | xargs ls

and on macOS at least, the escaped parens are unnecessary/do not work. This does:

ls | grep -i -E '(o)' | xargs ls

as does:

ls | grep -i -e '\(o\)' | xargs ls

Is this a BSD issue?

@abo-abo

This comment has been minimized.

Owner

abo-abo commented Nov 21, 2017

Thanks for the report. I added the missing logic. Please test.

@aaronjensen

This comment has been minimized.

Contributor

aaronjensen commented Nov 21, 2017

Yes, that worked, thank you! I believe this should also be applied to counsel-git-occur

@abo-abo abo-abo closed this in 5b270c6 Nov 21, 2017

@abo-abo

This comment has been minimized.

Owner

abo-abo commented Nov 21, 2017

Thanks.

@yqrashawn

This comment has been minimized.

yqrashawn commented Nov 26, 2017

Seems this broke ivy-occur on my macos, I'm using exa as ls.

Debugger entered--Lisp error: (wrong-type-argument stringp (("test" . t)))
  string-match("\\\\)\\|\\\\(\\|[()]" (("test" . t)) 0)
  counsel-unquote-regex-parens((("test" . t)))
  (format "ls | grep -i -E '%s' | xargs ls" (counsel-unquote-regex-parens ivy--old-re))
  (counsel-cmd-to-dired (format "ls | grep -i -E '%s' | xargs ls" (counsel-unquote-regex-parens ivy--old-re)))
  counsel-find-file-occur()
  ivy-occur()
  funcall-interactively(ivy-occur)
  call-interactively(ivy-occur nil nil)
  command-execute(ivy-occur)
  read-from-minibuffer("Find file: " nil (keymap (keymap (8 . counsel-up-directory) (C-backspace . counsel-up-directory) (67108991 . counsel-up-directory)) keymap (16 . ivy-previous-history-element) (14 . ivy-next-history-element) (escape . minibuffer-keyboard-quit) (12 . ivy-alt-done) (33554440 keymap (113 . help-quit) (118 . describe-variable) (119 . where-is) (116 . help-with-tutorial) (115 . describe-syntax) (114 . info-emacs-manual) (80 . describe-package) (112 . finder-by-keyword) (110 . view-emacs-news) (111 . describe-symbol) (109 . describe-mode) (108 . view-lossage) (107 . describe-key) (52 keymap (105 . info-other-window)) (105 . info) (104 . view-hello-file) (103 . describe-gnu-project) (102 . describe-function) (101 . view-echo-area-messages) (100 . apropos-documentation) (99 . describe-key-briefly) (98 . describe-bindings) (97 . apropos-command) (83 . info-lookup-symbol) (76 . describe-language-environment) (75 . Info-goto-emacs-key-command-node) (73 . describe-input-method) (70 . Info-goto-emacs-command-node) (67 . describe-coding-system) (28 . describe-input-method) (23 . describe-no-warranty) (20 . view-emacs-todo) (16 . view-emacs-problems) (15 . describe-distribution) (14 . view-emacs-news) (13 . view-order-manuals) (6 . view-emacs-FAQ) (5 . view-external-packages) (4 . view-emacs-debugging) (3 . describe-copying) (1 . about-emacs) (63 . help-for-help) (46 . display-local-help) (f1 . help-for-help) (help . help-for-help) (8 . help-for-help)) (8 . "\177") (11 . ivy-previous-line) (3 keymap (19 . ivy-rotate-sort) (1 . ivy-toggle-ignore) (15 . ivy-occur)) (67108903 . ivy-avy) (33554464 . ivy-restrict-to-matches) (15 . spacemacs/ivy-transient-state/body) (22 . ivy-scroll-up-command) (prior . ivy-scroll-down-command) (next . ivy-scroll-up-command) (7 . minibuffer-keyboard-quit) (32 . self-insert-command) (18 . ivy-reverse-i-search) (19 . ivy-next-line-or-history) (remap keymap (describe-mode . ivy-help) (kill-ring-save . ivy-kill-ring-save) (kill-line . ivy-kill-line) (scroll-down-command . ivy-scroll-down-command) (scroll-up-command . ivy-scroll-up-command) (end-of-buffer . ivy-end-of-buffer) (beginning-of-buffer . ivy-beginning-of-buffer) (kill-word . ivy-kill-word) (forward-char . ivy-forward-char) (delete-char . ivy-delete-char) (backward-kill-word . ivy-backward-kill-word) (backward-delete-char-untabify . ivy-backward-delete-char) (delete-backward-char . ivy-backward-delete-char) (previous-line . ivy-previous-line) (next-line . ivy-next-line)) (9 . ivy-partial-or-done) (10 . ivy-next-line) (27 keymap (8388640 . spacemacs/ivy-transient-state/body) (32 . hydra-ivy/body) (1 . ivy-read-action) (15 . ivy-dispatching-call) (111 . ivy-dispatching-done-hydra) (105 . ivy-insert-current) (106 . ivy-yank-word) (114 . ivy-toggle-regexp-quote) (16 . ivy-previous-line-and-call) (14 . ivy-next-line-and-call) (118 . ivy-scroll-down-command) (112 . ivy-previous-history-element) (110 . ivy-next-history-element) (10 . ivy-immediate-done) (13 . ivy-call)) (13 . ivy-done)) nil file-name-history)
  ivy-read("Find file: " read-file-name-internal :matcher counsel--find-file-matcher :initial-input nil :action #f(compiled-function (x) #<bytecode 0x458fd0a1>) :preselect nil :require-match confirm-after-completion :history file-name-history :keymap (keymap (8 . counsel-up-directory) (C-backspace . counsel-up-directory) (67108991 . counsel-up-directory)) :caller counsel-find-file)
  counsel-find-file()
  funcall-interactively(counsel-find-file)
  call-interactively(counsel-find-file nil nil)
  command-execute(counsel-find-file)
@abo-abo

This comment has been minimized.

Owner

abo-abo commented Nov 26, 2017

@yqrashawn Please open a new issue with more details.

@aaronjensen

This comment has been minimized.

Contributor

aaronjensen commented Nov 26, 2017

Looks like maybe counsel-unquote-regex-parens may need to handle re's from "re-seq" as taken by ivy-re-match.

@yqrashawn

This comment has been minimized.

yqrashawn commented Nov 27, 2017

@abo-abo #1322 seems it has nothing to do with exa.
@aaronjensen You mean the ivy--old-re is right but counsel-unquote-regex-parens can't handle it?

@aaronjensen

This comment has been minimized.

Contributor

aaronjensen commented Nov 27, 2017

I believe so yes, though I don't know how to repro it.

From the docstring:

Documentation:
Store the old regexp.
Either a string or a list for ‘ivy-re-match’.
@yqrashawn

This comment has been minimized.

yqrashawn commented Nov 27, 2017

It works fine with emacs -Q when

(load-file "~/.emacs.d/elpa/counsel-20171125.36/counsel-autoloads.el")
(load-file "~/.emacs.d/elpa/ivy-20171113.1024/ivy-autoloads.el")
(load-file "~/.emacs.d/elpa/swiper-20171124.804/swiper-autoloads.el")

M-x counsel-find-file some input
ivy-occur

@aaronjensen So I don't think it's a bug. Any idea?

@yqrashawn

This comment has been minimized.

yqrashawn commented Nov 27, 2017

@aaronjensen I'm using spacemacs develop branch's HEAD version, just can't find reason why the ivy--re-old set to list rather than string under my configuration. Checked spacemacs config and my private one.

@aaronjensen

This comment has been minimized.

Contributor

aaronjensen commented Nov 27, 2017

@yqrashawn it'd be best to have this discussion in #1322. That said, I'm not familiar enough w/ swiper, I'm only going off of the docstring I saw.

@patbl

This comment has been minimized.

patbl commented Dec 7, 2017

I'm on MacOS, and it seems that its version of xargs lacks the -d feature.

xargs: illegal option -- d
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
             [-L number] [-n number [-x]] [-P maxprocs] [-s size]
             [utility [argument ...]]

swiper/counsel.el

Line 1729 in c101525

"ls | grep -i -E '%s' | xargs -d '\n' ls"

https://superuser.com/questions/467176/replacement-for-xargs-d-in-osx

@abo-abo

This comment has been minimized.

Owner

abo-abo commented Dec 7, 2017

@patbl I added a new var that you can customize for OSX.

@aaronjensen

This comment has been minimized.

Contributor

aaronjensen commented Dec 10, 2017

@abo-abo as far as I can tell, the -d '\n' isn't necessary in linux--it does the same thing w/ or w/o it. That'd make it cross-platform, unless I'm missing something.

@abo-abo

This comment has been minimized.

Owner

abo-abo commented Dec 10, 2017

@aaronjensen The change -d \n was introduced in #1323. It's to prevent problems for files with spaces in them.

If you want, add a PR with a check for system-type that automatically sets the default the value you want on OSX. I don't want Linux to have a less useful command just because OSX doesn't have the same command.

@aaronjensen

This comment has been minimized.

Contributor

aaronjensen commented Dec 10, 2017

@abo-abo can you try this out and see if it works for you:

    "ls | grep -i -E '%s' | tr '\\n' '\\0' | xargs -0 ls"

abo-abo added a commit that referenced this issue Dec 11, 2017

counsel.el (counsel-find-file-occur-cmd): More portable
xargs doesn't have a "-d" flag on OSX.

Fixes #1299
@abo-abo

This comment has been minimized.

Owner

abo-abo commented Dec 11, 2017

@aaronjensen Works for me. Applied, thanks.

@aaronjensen

This comment has been minimized.

Contributor

aaronjensen commented Dec 11, 2017

Awesome, no problem. Thanks!

@patbl

This comment has been minimized.

patbl commented Jan 2, 2018

MacOS's ls doesn't have the --group-directories-first option:

➜ ls --group-directories-first
ls: illegal option -- -
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]

That was introduced here.

@patbl

This comment has been minimized.

patbl commented Jan 2, 2018

Also, when I change the command to omit --group-directories-first, it still doesn't really work.

(setq counsel-find-file-occur-cmd "ls -a | grep -i -E '%s' | tr '\\n' '\\0' | xargs -0 ls -d")

The file names are duplicated in a dired buffer:

image

If I try to select any of them, there's this error message:

command-execute: Wrong type argument: commandp, dired-single-buffer

It could be that I have something misconfigured.

ETA: This was the line that was causing the duplication:

(add-hook 'dired-mode-hook 'revert-buffer)

I don't know why I added that, but things seem to work fine when I get rid of it.

@abo-abo

This comment has been minimized.

Owner

abo-abo commented Jan 2, 2018

@patbl You can open your favorite shell and play around with the cmd until it works. Just substitute %s for the thing to grep, and handle escapes.

Example:

$ ls -a | grep -i -E '' | tr '\n' '\0' | xargs -0 ls -d -alh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment