scmbreeze / scm_breeze

Adds numbered shortcuts to the output git status, and much more
https://madebynathan.com/2011/10/19/git-shortcuts-like-youve-never-seen-before/
MIT License
2.82k stars 192 forks source link

exec_scmb_expand_args ls_with_file_shortcuts doesn't set $e1 variable when output is piped #254

Closed HaleTom closed 5 years ago

HaleTom commented 5 years ago

exec_scmb_expand_args ls_with_file_shortcuts doesn't set $e\<number> variables when the command's output is piped:

% mkdir empty
% cd empty
% touch file
% # Show it working correctly
% e1=''
% exec_scmb_expand_args ls_with_file_shortcuts > /dev/null
% echo $e1
/tmp/empty/file
%  # The above works as expected. But piping to `cat` doesn't:
% e1=''
% exec_scmb_expand_args ls_with_file_shortcuts | cat > /dev/null
% echo $e1

%

My use case for this is:

alias ll='exec_scmb_expand_args ls_with_file_shortcuts | grcat conf.ls'

This uses the Generic Colouriser grc to colour the output of ll.

ghthor commented 5 years ago

Ok, this is interesting. I do see your use case and I think it's a valid one that we should support.

Could this have something to do with a subshell dilemma?

Also, bit confused here, this might just show my current knowledge distance from scm_breeze's internals, but the following functions as such, sanity check me?

$ mkdir -p empty && touch empty/file && cd empty                                                        
$ ls_with_file_shortcuts 
-rw-r--r-- 1 ghthor ghthor 0 Aug 24 11:03 [1]  file
$ env | grep ^e1=
e1=/home/ghthor/.scm_breeze/empty/file
$ mkdir -p nested && touch nested/empty_file
$ ls_with_file_shortcuts
drwxr-xr-x 1 ghthor ghthor 20 Aug 24 11:04 [1]  nested
-rw-r--r-- 1 ghthor ghthor  0 Aug 24 11:03 [2]  file
$ env | grep ^e1=
e1=/home/ghthor/.scm_breeze/empty/nested/nested
$ exec_scmb_expand_args ls_with_file_shortcuts 1
-rw-r--r-- 1 ghthor ghthor 0 Aug 24 11:04 [1]  empty_file
$ env | grep ^e1=
e1=/home/ghthor/.scm_breeze/empty/nested/empty_file

So the use case for this is like a nested recursive expansion. Question, if you make your alias into a shell function does it work?

function ls_recursive_expand() {
  exec_scmb_expand_args ls_with_file_shortcuts ${@} | grcat conf.ls
}
HaleTom commented 5 years ago

Yup, good call on the subshell setting variables not available to the parent.

pelim commented 2 years ago

quickfix: brew install coreutils