Skip to content

Instantly share code, notes, and snippets.

@ricewind012
Last active January 7, 2025 12:58
Show Gist options
  • Select an option

  • Save ricewind012/754c71aa70f0437b4bfaba0c3d5a2552 to your computer and use it in GitHub Desktop.

Select an option

Save ricewind012/754c71aa70f0437b4bfaba0c3d5a2552 to your computer and use it in GitHub Desktop.
windows letters prompt with /etc/fstab support
# Have to rerun every time /etc/fstab gets changed
XDG_CACHE_HOME=${XDG_CACHE_HOME:=$HOME/.cache}
win_script=$XDG_CACHE_HOME/win_dirs_cached
[[ -f $win_script ]] || win_dirs > "$win_script"
. "$win_script"
get_win_prompt() {
local found=0
for key in "${!win_dirs[@]}"; do
[[ ! $PWD =~ ${win_dirs[$key]} ]] && continue
win_dir=${win_dirs[$key]}
win_letter=$key
found=1
done
actual_pwd=${PWD#"$win_dir"}
if (( ! found )); then
win_dir=
win_letter=C
fi
}
PROMPT_COMMAND=get_win_prompt
PS1='$win_letter:${actual_pwd//\//\\\\}> '
#!/bin/sh
i=0
printf 'declare -A win_dirs\n'
while read -r fs dir type options dump pass; do
[ "${fs%"${fs#?}"}" = '#' ] && continue
[ "$dir" = / ] && continue
[ "$type" = tmpfs ] && continue
case $i in
0) d=D ;;
1) d=E ;;
2) d=F ;;
3) d=G ;;
4) d=H ;;
5) d=I ;;
6) d=J ;;
7) d=K ;;
8) d=L ;;
9) d=M ;;
10) d=N ;;
11) d=O ;;
12) d=P ;;
13) d=Q ;;
14) d=R ;;
15) d=S ;;
16) d=T ;;
17) d=U ;;
18) d=V ;;
19) d=W ;;
20) d=X ;;
21) d=Y ;;
22) d=Z ;;
esac
i=$(( i + 1 ))
printf 'win_dirs[%s]="%s"\n' "$d" "$dir"
done < /etc/fstab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment