shyiko/commacd

I love it but... I'd like , to always give me the shortest match

lioPixiumDigital opened this issue · 0 comments

It'd be nice to add an option to match the shortest foldername:
e.g. given three folders

  • getmybil (8c)
  • kill.bill.the-movie (lotsof c.)
  • gerbil (6c)

, bil would match gerbil

I implemented it locally by modifying _commacd_forward()

  if [[ ${#dir[@]} -gt 1 ]]; then
    # https://github.com/shyiko/commacd/issues/12
    trap 'trap - SIGINT; stty '"$(stty -g)" SIGINT

    # Lio added: take shortst match
    dirf=''
    for diri in "${dir[@]}"; do
      printf "candidate: %s" "${diri}" 
      if [[ "${dirf}" == '' ]] || [ "${#dirf}" -gt "${#diri}" ]; then
        printf "*";
        dirf="${diri}"
      fi
      printf "\n";
    done
    dir="${dirf}"
    # lio chose shortest

    #dir=$(_commacd_choose_match "${dir[@]}")

    # make sure trap is removed regardless of whether read -e ... was
    # interrupted or not
    trap - SIGINT
    if [[ -z "$dir" ]]; then return 1; fi
  fi