@@ -951,6 +951,24 @@ get_best_fuzzy_match(char *filename, const char *dirname, char *d_name,
951951 return 1 ;
952952}
953953
954+ static inline int
955+ skip_first_word (const mode_t type , const int line_buffer_has_space )
956+ {
957+ return (((conf .suggestions == 1 && words_num == 1 )
958+ || line_buffer_has_space == 0 )
959+ && ((type == DT_DIR && conf .autocd == 0 )
960+ || (type != DT_DIR && conf .auto_open == 0 )));
961+ }
962+
963+ static inline int
964+ do_regular_matching (const char * filename )
965+ {
966+ return (rl_point < rl_end || conf .fuzzy_match == 0
967+ || (* filename == '.' && filename [1 ] == '.' )
968+ || * filename == '-'
969+ || (tabmode == STD_TAB && !(flags & STATE_SUGGESTING )));
970+ }
971+
954972/* This is the filename_completion_function() function of an old Bash
955973 * release (1.14.7) modified to fit Clifm's needs */
956974/* state is zero before completion, and 1 ... n after getting
@@ -982,8 +1000,6 @@ my_rl_path_completion(const char *text, int state)
9821000 static int line_buffer_has_space = 0 ;
9831001 static int conf_suggestions = 0 ;
9841002 static int conf_fuzzy_match = 0 ;
985- static int conf_auto_open = 0 ;
986- static int conf_autocd = 0 ;
9871003
9881004 /* Dequote string to be completed (text), if necessary. */
9891005 if (strchr (text , '\\' )) {
@@ -1012,8 +1028,6 @@ my_rl_path_completion(const char *text, int state)
10121028
10131029 conf_suggestions = conf .suggestions ;
10141030 conf_fuzzy_match = conf .fuzzy_match ;
1015- conf_auto_open = conf .auto_open ;
1016- conf_autocd = conf .autocd ;
10171031
10181032 free (dirname );
10191033 free (filename );
@@ -1101,10 +1115,9 @@ my_rl_path_completion(const char *text, int state)
11011115 type = ent -> d_type ;
11021116#endif /* !_DIRENT_HAVE_D_TYPE */
11031117
1104- if (((conf_suggestions == 1 && words_num == 1 )
1105- || line_buffer_has_space == 0 )
1106- && ((type == DT_DIR && conf_autocd == 0 )
1107- || (type != DT_DIR && conf_auto_open == 0 )))
1118+ /* First word: skip dirs if autocd is off, and non-dirs if
1119+ * auto-open is off. */
1120+ if (skip_first_word (type , line_buffer_has_space ) == 1 )
11081121 continue ;
11091122
11101123 /* Only dir names for cd */
@@ -1126,9 +1139,7 @@ my_rl_path_completion(const char *text, int state)
11261139 else if (is_open_cmd == 1 )
11271140 match = filter_open_cmd (dirname , ename , tmp , type );
11281141
1129- /* If 'trash', allow only reg files, dirs, symlinks, pipes
1130- * and sockets. You should not trash a block or a character
1131- * device. */
1142+ /* If 'trash', skip block and character devices. */
11321143 else if (is_trash_cmd == 1 )
11331144 match = (type != DT_BLK && type != DT_CHR );
11341145
@@ -1139,15 +1150,10 @@ my_rl_path_completion(const char *text, int state)
11391150
11401151 /* If there is at least one char to complete (e.g., "cd .[TAB]") */
11411152 else {
1142- if (rl_point < rl_end || conf_fuzzy_match == 0
1143- || (* filename == '.' && filename [1 ] == '.' )
1144- || * filename == '-'
1145- || (tabmode == STD_TAB && !(flags & STATE_SUGGESTING ))) {
1146- /* Regular matching. */
1153+ if (do_regular_matching (filename ) == 1 ) {
11471154 if (check_match (filename , ename , filename_len ) == 0 )
11481155 continue ;
1149- } else {
1150- /* Fuzzy matching. */
1156+ } else { /* Fuzzy matching. */
11511157 if (flags & STATE_SUGGESTING ) {
11521158 if (get_best_fuzzy_match (filename , dirname , ename ,
11531159 filename_len , fuzzy_str_type , & best_fz_score ) == 0 )
0 commit comments