File tree Expand file tree Collapse file tree 1 file changed +20
-10
lines changed Expand file tree Collapse file tree 1 file changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -1659,6 +1659,25 @@ _fstypes()
1659
1659
[[ $fss ]] && COMPREPLY+=($( compgen -W " $fss " -- " $cur " ) )
1660
1660
}
1661
1661
1662
+ # Get absolute path to a file, with rudimentary canonicalization.
1663
+ # No symlink resolution or existence checks are done;
1664
+ # see `_comp_realcommand` for those.
1665
+ # @param $1 The file
1666
+ # @var[out] ret The path
1667
+ _comp_abspath ()
1668
+ {
1669
+ ret=$1
1670
+ case $ret in
1671
+ /* ) ;;
1672
+ ../* ) ret=$PWD /${ret: 3} ;;
1673
+ * ) ret=$PWD /$ret ;;
1674
+ esac
1675
+ while [[ $ret == * /./* ]]; do
1676
+ ret=${ret// \/ .\/ / \/ }
1677
+ done
1678
+ ret=${ret// +(\/ )/ \/ }
1679
+ }
1680
+
1662
1681
# Get real command.
1663
1682
# Command is the filename of command in PATH with possible symlinks resolved
1664
1683
# (if resolve tooling available), empty string if command not found.
@@ -1677,16 +1696,7 @@ _comp_realcommand()
1677
1696
elif type -p readlink > /dev/null; then
1678
1697
ret=$( readlink -f " $file " )
1679
1698
else
1680
- ret=$file
1681
- if [[ $ret == * /* ]]; then
1682
- if [[ $ret == ./* ]]; then
1683
- ret=$PWD /${file: 2}
1684
- elif [[ $ret == ../* ]]; then
1685
- ret=$PWD /${file: 3}
1686
- elif [[ $ret != /* ]]; then
1687
- ret=$PWD /$file
1688
- fi
1689
- fi
1699
+ _comp_abspath " $file "
1690
1700
fi
1691
1701
}
1692
1702
You can’t perform that action at this time.
0 commit comments