fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
a53db7256
master
1# localization: skip(private) 2# 3# This function only emits completions that might result from matches against $CDPATH. We rely on 4# the core file name completion logic to include all other possible matches. 5function __fish_complete_cd -d"Completions for the cd command" 6set -q CDPATH[ 1 ] 7or return 0 # no CDPATH so rely solely on the core file name completions 8 9set -l token( commandline -ct) 10if string match -qr'^\.{0,2}/.*' --$token 11# Absolute path or explicitly relative to the current directory. Rely on the builtin file 12# name completions since we no longer exclude them from the `cd` argument completion. 13return 14end 15 16# Relative path. Check $CDPATH and use that as the description for any possible matches. 17# We deliberately exclude the `.` path because the core file name completion logic will include 18# it when presenting possible matches. 19set -l cdpath( string match -v'.' --$CDPATH ) 20 21# Remove the CWD if it is in CDPATH since, again, the core file name completion logic will 22# handle it. 23set -l cdpath( string match -v --$PWD $cdpath ) 24set -q cdpath[ 1 ] 25or return 0 26 27# TODO: There's a subtlety regarding descriptions - if $cdpath[1]/foo and $cdpath[2]/foo 28# exist, we print both but want the first description to win - this currently works, but 29# is not guaranteed. 30for cdpathin $cdpath 31# Replace $HOME with "~". 32set -l desc( string replace -r --"^ $HOME " "~" " $cdpath " ) 33# This assumes the CDPATH component itself is cd-able. 34for din $cdpath /$token */ 35# Remove the cdpath component again. 36test -x $d 37and printf "%s\tCDPATH %s\n" ( string replace -r"^ $cdpath /" "" --$d ) $desc 38end 39end 40end