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

option to set "root" path #70

Open
nkh opened this issue Jul 7, 2023 · 6 comments
Open

option to set "root" path #70

nkh opened this issue Jul 7, 2023 · 6 comments

Comments

@nkh
Copy link

nkh commented Jul 7, 2023

it seems that the location when running lscolors changes the way its input is colored

screenshot_2023-07-07_12-12-14

when in another directory and with the same input, colors differ; also note that the some files are colored as they should, one of the files is executable and doesn't have the same color but that's understandable.

lscolors_no_color

I run lscolors in a subshell as a fix it but it may surprise some users and it would be more usable if the result is the same, and for users without a sub shell an option to set the "root" path may be helpful.

@sharkdp
Copy link
Owner

sharkdp commented Jul 23, 2023

Please tell us exactly how you run lscolors

@nkh
Copy link
Author

nkh commented Jul 23, 2023

In many ways but most often in a pipe.

You may not remember me but I'm the one who asked you to extract lscolors as a utility.

config/ftl/etc/viewers/core:ptype()     { mime_get ; psplit "echo ${f@Q} | lscolors ; echo 'mime type: $mtype' ; echo -n 'file type: '; file -b ${n@Q} ; stat -c %s ${n@Q} | numfmt --to=iec ; read -sn 100" ; }
config/ftl/etc/core/ftl:filter2()   { ftl_sort | tee >(cat >&4) | vfiles_clr | filter_c | lscolors >&5 ; }
config/ftl/etc/core/commands:gmark_fzf()		{ [[ -e $ftl_root/marks ]] && go_loop f fzf "$({ cat $ftl_root/marks ; gmark_fzf_user ; } | lscolors | fzf-tmux $fzf_opt --cycle -m --expect=ctrl-t --ansi)" ; }
config/ftl/etc/core/commands:history_go()		{ h=$fs/history ; dedup $h && go_loop f fzf "$(<$h lscolors | fzf-tmux $fzf_opt --tac --ansi --expect=ctrl-t)" ; }
config/ftl/etc/core/commands:ghistory()		{ h=$ghist ; dedup $h && go_loop f fzf "$(<$h lscolors | fzf-tmux $fzf_opt --tac --ansi --expect=ctrl-t)" ; }
config/ftl/etc/core/commands:ghistory_edit()		{ dedup $ghist && rg -v -x -F -f <(<$ghist lscolors | fzf-tmux $fzf_opt --tac -m --ansi) $ghist | sponge $ghist ; }
config/ftl/etc/core/commands:mark_fzf()		{ go_loop f fzf "$({ gmark_fzf_user ; printf "%s
" "${marks[@]}" ; } | sort -u | lscolors | fzf-tmux $fzf_opt -m --expect=ctrl-t --ansi)" ; }
config/ftl/etc/core/commands:selection_ext_fzf()	{ fzf_tag T "$(fd -H -I -d1 | rg "\.$e$" | lscolors | fzf-tmux $fzf_opt -m --ansi --marker '')" ; list ; }
config/ftl/etc/core/commands:selection_ext_all_fzf()	{ fzf_tag T "$(fd -H -I | rg "\.$e$" | lscolors | fzf-tmux $fzf_opt -m --ansi --marker '')" ; list ; }
config/ftl/etc/core/commands:selection_goto()	{ tag_check && go_loop f fzf "$(printf "%s
" "${!tags[@]}" | sort -u | lscolors | fzf-tmux $fzf_opt --tac --ansi --expect=ctrl-t)" ; }
config/ftl/etc/core/commands:selection_untag_fzf()	{ tag_check && { fzf_tag U "$(printf "%s
" "${!tags[@]}" | lscolors | fzf-tmux $fzf_opt -m --ansi --marker '')" ; list ; } ; }
config/ftl/etc/filters/by_file_reset_dir:			lscolors | fzf-tmux -p 80% --cycle -m --ansi --info=inline --layout=reverse --bind ctrl-s:select-all\
config/ftl/etc/bin/fzf_mv_rm:<"$fzf_mv_rc" lscolors | fzf-tmux $fzf_opt > /tmp/$$_fzf_mv && rg -v -x -F -f /tmp/$$_fzf_mv "$fzf_mv_rc" | sponge "$fzf_mv_rc"
config/ftl/etc/bin/frl:find . -maxdepth $frl_max_depth -type p,d,f,l -xtype p,d,f,l | sed -e '/^\.$/d' -e 's~^\.\/~~' | rg --no-heading --smart-case "$1" --color=always --colors 'match:fg:51' | lscolors
config/ftl/etc/bin/fzf_mv:to=$( cat "$fzf_mv_rc" 2>&- | awk '!seen[$0]++' | lscolors | fzf-tmux -0 -1 $fzf_opt)
config/ftl/etc/bin/third_party/plc:	uses 'lscolors' or File::LS_colors
config/ftl/etc/bin/third_party/plc:my $pid = open2(*COLORED, *LSCOLORS, "lscolors");
config/ftl/etc/filters/by_extension:			sort -u | { echo "-no_extension-" ; cat ; } | lscolors | \
config/ftl/etc/filters/by_file_global_reset_dir:			lscolors | fzf-tmux -p 80% --cycle -m --ansi --info=inline --layout=reverse --bind ctrl-s:select-all \
config/ftl/etc/filters/by_file:			lscolors | fzf-tmux -p 80% --cycle -m --ansi --info=inline --layout=reverse --bind ctrl-s:select-all \
config/ftl/etc/filters/by_file_global:			lscolors | fzf-tmux -p 80% --cycle -m --ansi --info=inline --layout=reverse --bind ctrl-s:select-all \
config/ftl/etc/filters/by_no_extension:			sort -u | { echo "-without_extension-" ; cat ; } | lscolors | \
config/ftl/etc/filters/by_all_files:			find -printf "%p
" | grep -v '^\.$' | sed 's ^./  ' | sort -u | lscolors | \
config/ftl/etc/bindings/leader_git:go_loop f fzf "$(cd "$git_root" ; git -c color.status=always status -s | lscolors | fzf-tmux $fzf_opt -m --expect=ctrl-t --ansi | sed 's#...#'$git_root'/#')"
config/ftl/etc/bindings/lib/extra:tsplit "{ echo -n '  File: ' ; echo ${n@Q} | lscolors ; hsize=\$(echo -n 'H_size: ' ; stat -c %s '$n' | numfmt --to=iec) ; stat '$n' | sed -e '/File:/d' -e \"s/Device:/\$hsize            Device:/\" -e 's/IO Block/IO_Block/' ; echo '  mime: $mtype' ; echo -n '  type: ' ; file -b ${n@Q} ; } | piper --global '[A-Za-z-_]+: ' 'blue' '\d+\ ?x\ ?\d+' 'yellow' ; read -sn 1"
config/ftl/bindings/tmsu:tmsu_goto() { go_loop f fzf "$(tmsu_table2 | lscolors | fzf-tmux $fzf_opt -m --ansi --expect=ctrl-t --preview 'lscolors {}' --preview-window noborder:wrap:down:4 | sed 's/:.*//')" ; }
config/ftl/bindings/fzf_pane_preview:	lscolors | \

@tavianator
Copy link
Contributor

You could use a subshell for this, e.g.

fd | (cd dir && lscolors) | ...

However, I do notice one quality-of-life thing we could improve: right now if any directory component doesn't exist, we treat it like a normal file. Presumably we should only do that for the final component, and everything else should default to the directory color.

@nkh
Copy link
Author

nkh commented Jul 24, 2023

@tavianator

from my first post

I run lscolors in a subshell as a fix it ...

but it may surprise some users ...

and it would be more usable if the result is the same  ...

and for users without a sub shell an option to set the "root" path may be helpful.

And yes please paths that don't exists should still look like paths. For executable files a "root" path would be necessary as I suggested.

this is useful when one has a list of paths to display, want to remove parts of the path (because it's too long for example) and still have colors.

@sharkdp
Copy link
Owner

sharkdp commented Aug 21, 2023

Thank you for reporting this. It would be of great help if you could a small example on how to reproduce this. And maybe summarize the suggested improvements (add root path option + colorize non-terminal folders + ...).

@nkh
Copy link
Author

nkh commented Aug 21, 2023

Hi, sorry I was clear enough about the context.

mkdir subdir 
touch subdir/f.jpg
touch subdir/f.exe
chmod a+x subdir/f.exe

fd . subdir > found
<found lscolors

mkdir other_sub
cd other_sub
<../found lscolors # colors will differ here

Possible improvements:

  • path could always be colored if it looks like a path, as named by tavianator
  • files could always be colored (they are)
  • files that need to be accessed could use the --root option
    • but "root" is pre-pended to all input
root="$PWD"
cd a_galaxy_far_far_away 
<found lscolors --root "$root"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants