How to make this script run in dmenu?

94 views Asked by At

I want to run shell script that will append my movie names in a watched.txt file which will help me to keep record of my watched movies. For this I want this script to run in dmenu and not in terminal. But the script works correctly only when I am running the command in terminal and not in dmenu. I have all my scripts saved in bin directory inside my ~/ and they all worked whenever they are run using dmenu, but not this one. Every time I am running "watched" the script in my dmenu it fails to execute the first if statement and only shows the output of the else statement which is not inside movies directory.

I have my bin dir in $PATH as well

Please let me know what is the issue and where to look at.

#!/bin/sh

parent_dir=$(basename "$(dirname "$PWD")")
if [ "$parent_dir" = "movies" ];then
        choice=$(echo -e "yes\nno" | dmenu -p Watched?)

        if [ "$choice" = "yes" ];then
                echo "$(basename "$PWD")" >> /home/sinjini/movies/watched.txt && nl -s: -p ~/movies/watched.txt | dmenu -p "watched movies" -l 5
        else
                 nl -s: -p ~/movies/watched.txt | dmenu -p "watched movies" -l 5
        fi
else
        echo not inside movies directory | dmenu -p watched
fi

I tried running the script inside the correct directory in my terminal and in dmenu, it runs exactly the way it suppose to run when run in terminal but fails in dmenu. What I think is that since my script deals with current directories and its parent directories, thus terminal gives the correct value for $PWD and dmenu cannot have that value for some reason. I might be wrong though. Thanks

0

There are 0 answers