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

path filter --inside DIRECTORY #9557

Open
0ion9 opened this issue Feb 9, 2023 · 0 comments
Open

path filter --inside DIRECTORY #9557

0ion9 opened this issue Feb 9, 2023 · 0 comments

Comments

@0ion9
Copy link
Contributor

0ion9 commented Feb 9, 2023

Checking whether one path is inside another (as in '/home/me/Documents is inside /home/me') is a simple, reasonably common task with several possible ways to do it, some of which are subtly unreliable. It would be nice to standardize it.

Considering the current push towards Rust, which would be kept simple by minimizing added functionality, I'll just put a basic fish implementation here for the moment :

function path-inside --description 'return paths which are inside $argv[1]'
  set -l parent (path resolve -- $argv[1])/
  set -l plen (string length -- $parent)
  set -l nunpassed 0
  for p in $argv[2..]
    if [ (string sub -l $plen -- (path resolve -- $p)) = $parent ] 
      printf %s\n $p
    else
      set nunpassed (math $nunpassed+1)
    end
  end
  [ $nunpassed -lt (count $argv[2..]) ]
end
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

1 participant