0

how can I find which files tcsh reads to TAB complete the second word of a command, as opposed to the first word.

I know I can just use whereis complete to see the path to *.1.gz file, but that is not specific enough to say which files are being used.

On the other hand, if I use locate complete, I am given a list of a couple hundred files, many of which aren't executable.

1

I'd use strace to capture the whole session, and pick up the keyboard-read by browsing the script output, and then find all of the open-calls after that. That works with Linux and some other systems. There's a similar trace for BSD's (MacOS is a different story though).

However, tcsh likely is not opening the files but listing them from the directory. strace would help with that, too. For instance, in a quick check I see it opening the current directory using openat

openat(AT_FDCWD, ".", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3

and then using the lstat function to determine what the entries of interest are (so that it can sort them, decide which are files versus directories, etc):

lstat("xterm.desktop", {st_mode=S_IFREG|0444, st_size=1921, ...}) = 0

The "." is the current directory. The program reads a list of directory entries which may be files, directories, symbolic links, etc., but those are not sorted (and types are unknown, until it uses stat/lstat to ask).

locate and whereis won't show useful data, since they do not use the same rules for finding the files as tcsh.

  • Okay, so I found the spot in strace when tab completed the word. I typed echot and it was completed to echotc. However, I cannot discern what files were accessed in the process. The only open command that I see inbetween is " openat(AT_FDCWD, ".", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3 ". – Alexander Wolf Sep 13 '18 at 3:24
  • st_mode is just telling me the file type and mode? Can I get further information on which files were actually consulted to excute TAB complete properly, after tcsh used lstat? – Alexander Wolf Sep 13 '18 at 19:11
  • You could read tcsh's source-code. Offhand, the reason why it does the lstat's is to determine which entries it can show. Assume it showed all of those for which the lstat was performed. – Thomas Dickey Sep 13 '18 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.