Created
October 1, 2025 19:41
-
-
Save pwwang/30e2790935e3a180a8a3b401201057c0 to your computer and use it in GitHub Desktop.
A command to get the cloud path with a path mounted by gcsfuse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function cpwd --description 'Print the cloud path of a mounted path' | |
| if test (count $argv) -gt 1 | |
| echo "Usage: cloudpath [mounted_path]" | |
| return 1 | |
| end | |
| if test (count $argv) -eq 0 | |
| set mounted_path (pwd) | |
| else | |
| set mounted_path $argv[1] | |
| end | |
| set mounted_path (realpath $mounted_path) | |
| if not test -d $mounted_path | |
| echo "Error: '$mounted_path' is not a valid directory." | |
| return 1 | |
| end | |
| set source_path | |
| set mpath $mounted_path | |
| while true | |
| set src (findmnt -rno SOURCE $mpath) | |
| if test -n "$src" | |
| if string match -rq '^ml-.+$' -- $src | |
| set source_path $src | |
| break | |
| end | |
| end | |
| set mpath (dirname $mpath) | |
| if test "$mpath" = "/" | |
| break | |
| end | |
| end | |
| if test -z "$source_path" | |
| echo "Error: '$mounted_path' is not on a gcsfuse mount or subdirectory of it." | |
| return 1 | |
| end | |
| set relative_path (realpath --relative-to=$mpath $mounted_path) | |
| if test -n "$relative_path" | |
| echo "gs://$source_path/$relative_path" | |
| else | |
| echo "gs://$source_path" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment