2

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 ?

1 Answer 1

10

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
    psvar[1]=red
  else
    psvar[1]=green
  fi
}
chpwd_functions+=(check_cwd_is_tmpfs)
check_cwd_is_tmpfs

PS1='%F{%1v}%~%F$ '
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .