I would like to change my zsh prompt color, if $PWD is currently on tmpfs mounted filesystem.

Lets say for example, /dev/shm is a tmpfs filesystem. I can confirm that:

$ grep /dev/shm /proc/mounts 
tmpfs /dev/shm tmpfs rw,nosuid,nodev,noexec,relatime,size=26307700k 0 0

so, when I am in /dev/shm, I can do:

grep -q "^tmpfs $PWD tmpfs " /proc/mounts

But that will not work, if I stand in /dev/shm/foo, or /dev/shm/foo/bar, and so on.

How can I check whether $PWD is on a tmpfs filesystem ?


On Linux, you should be able to do:

findmnt -no FSTYPE .

to return the type of the filesystem on .

The GNU implementation of stat (not zsh stat builtin) can also do it with:

command stat -fc %T .

So you could cache that information in an element of $psvar in a chpwd hook:

check_cwd_is_tmpfs() {
  if [[ $(command stat -fc %T .) = tmpfs ]]; then

PS1='%F{%1v}%~%F$ '
| improve this answer | |

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.