You could add something like this to the startup script of your default shell (mine is zsh, most people use bash, I guess, so you may have to tweak.)
Here's my bit of screen jiggery-pokery (in my .zshrc)
# Autoload screen if we aren't in it. (Thanks Fjord!)
if [[ $STY = '' ]] then screen -xRR; fi
I got this from somewhere on the interwebs (I don't recall where, and I don't know who Fjord is, but good on him.
With this you can close your iTerm window, and it will resume where you left off when you reopen it. I highly recommend reading the screen man page also.
Prior to OS X El Capitan 10.11, the code in /etc/bashrc
arranges to send an escape sequence at each prompt to tell Terminal what the current working directory is, but this code only percent-encodes spaces, which means that it doesn't work with characters that are not valid URL characters, which includes any non-ASCII characters like “Ü”:
update_terminal_cwd() {
# Identify the directory using a "file:" scheme URL,
# including the host name to disambiguate local vs.
# remote connections. Percent-escape spaces.
local SEARCH=' '
local REPLACE='%20'
local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
printf '\e]7;%s\a' "$PWD_URL"
}
On 10.11 and later, the code has been moved to /etc/bashrc_Apple_Terminal
and has been updated to percent-encode all characters that require it, so it can now work with characters like “Ü” (your example case works for me on 10.11.1):
update_terminal_cwd() {
# Identify the directory using a "file:" scheme URL, including
# the host name to disambiguate local vs. remote paths.
# Percent-encode the pathname.
local url_path=''
{
# Use LC_CTYPE=C to process text byte-by-byte. Ensure that
# LC_ALL isn't set, so it doesn't interfere.
local i ch hexch LC_CTYPE=C LC_ALL=
for ((i = 0; i < ${#PWD}; ++i)); do
ch="${PWD:i:1}"
if [[ "$ch" =~ [/._~A-Za-z0-9-] ]]; then
url_path+="$ch"
else
printf -v hexch "%02X" "'$ch"
# printf treats values greater than 127 as
# negative and pads with "FF", so truncate.
url_path+="%${hexch: -2:2}"
fi
done
}
printf '\\e]7;%s\\a' "file://$HOSTNAME$url_path"
}
[iTerm 2 apparently reads the working directory from the shell process state. This has the advantage that it works without any shell setup; however, it isn't guaranteed to be correct (there's no reason a shell's current working directory has to actually match the cwd it uses when executing a command, at any given moment), it doesn't work through indirect connections like ssh
or shells running within editors or screen multiplexers, and it can't read the directory from processes owned by other users—for example, if you use sudo -s
to create a root shell, it can't read the working directory from the root shell process. Furthermore, the program state only includes a file descriptor for the open directory, not the path that the shell is using for $PWD
, so you won't actually get the path you used to navigate to the current directory in some cases—e.g., if you traversed through a symbolic link.]
Best Answer
In the Terminal, at the start of the command line, tab completion is looking for an executable file that is on the PATH (unless a specific directory is indicated).
When you are looking in the Movies directory, and the current directory is likely not to be on the PATH so it will find the three files indicated.
In order to find out where these files are, you can use the
which
command:To find the contents of the current directory, you would type the
ls
command. That should list the files that are in the directory. For more information about all the files, typels -l
.Once you have a command shown, tab completion will look for a file in the current directory to use as an argument.
If you are looking to do something with a movie, you'll need a command. You might want to type
open
. So, typeopen S
tab, and it should do the tab completion magic for you. Theopen
command will open a file as if you double clicked on it. You can find out more about theopen
command by typingman open
.