Difference between revisions of "Document viewer script"
Viminator25 (talk | contribs) (UPDATE: Improve efficiency.) |
m (Correct syntax highlighting tags) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 7: | Line 7: | ||
== Source Code == | == Source Code == | ||
− | < | + | <syntaxhighlight lang="bash"> |
#!/bin/bash | #!/bin/bash | ||
Line 22: | Line 22: | ||
tabbed -cd -p -1 zathura "$1" -e 1>$xid_file & | tabbed -cd -p -1 zathura "$1" -e 1>$xid_file & | ||
if [ $focus ]; then | if [ $focus ]; then | ||
− | |||
while [ $num_wins -eq $(wmctrl -l | wc -l) ]; do | while [ $num_wins -eq $(wmctrl -l | wc -l) ]; do | ||
sleep 0.0001 | sleep 0.0001 | ||
done | done | ||
+ | read xid < $xid_file | ||
wmctrl -ir $xid -b add,maximized_vert,maximized_horz | wmctrl -ir $xid -b add,maximized_vert,maximized_horz | ||
fi | fi | ||
Line 40: | Line 40: | ||
fi | fi | ||
fi | fi | ||
− | </ | + | </syntaxhighlight> |
The script uses: | The script uses: | ||
Line 50: | Line 50: | ||
# [https://en.wikipedia.org/wiki/Wc_(Unix) wc], works with all versions. Needed for focusing window. (OPTIONAL) | # [https://en.wikipedia.org/wiki/Wc_(Unix) wc], works with all versions. Needed for focusing window. (OPTIONAL) | ||
− | There is only one option in this script: < | + | There is only one option in this script: <pre>focus</pre>, which will manage the zathura window to pop up whenever it is opened. |
== Installation == | == Installation == | ||
Line 56: | Line 56: | ||
Copy the above code into a <code>zathura.sh</code> script (or whatever you want) in either a <code>$PATH</code> directory or in your <code>$VIFM/scripts</code> directory. | Copy the above code into a <code>zathura.sh</code> script (or whatever you want) in either a <code>$PATH</code> directory or in your <code>$VIFM/scripts</code> directory. | ||
Then go into your vifm rc file and assign the file type: | Then go into your vifm rc file and assign the file type: | ||
− | < | + | <syntaxhighlight lang="vim"> |
filextype *.pdf,*.djvu,*.epub zathura.sh %f & | filextype *.pdf,*.djvu,*.epub zathura.sh %f & | ||
− | </ | + | </syntaxhighlight> |
== For Other Kinds of Documents == | == For Other Kinds of Documents == | ||
Line 65: | Line 65: | ||
Paste this code into a shell script called <code>zadocx.sh</code> for viewing files of the <code>.docx</code> format. | Paste this code into a shell script called <code>zadocx.sh</code> for viewing files of the <code>.docx</code> format. | ||
− | < | + | <syntaxhighlight lang="bash"> |
#!/bin/bash | #!/bin/bash | ||
Line 75: | Line 75: | ||
shift | shift | ||
done | done | ||
− | </ | + | </syntaxhighlight> |
{{NOTE|text=This script will '''delete''' your docx file, so you may want to back it up or remove the 'rm' line}} | {{NOTE|text=This script will '''delete''' your docx file, so you may want to back it up or remove the 'rm' line}} | ||
Then assign the file type in your rc file in the same manner as the last one. | Then assign the file type in your rc file in the same manner as the last one. |
Latest revision as of 12:03, 31 August 2021
This script is for viewing files that are to be opened with zathura.
What's nice about this is that it puts everything into a tabbed interface for you and auto-maximizes the window.
These scripts are designed to work with visual selections as well, so you can open up as many documents as you wish all at once.
Source Code[edit]
#!/bin/bash
# This script is for launching zathura in a tabbed enviornment,
# and placing every subsequent instance of zathura in that enviornment.
# Focus zathura on opening a new file
focus=1
xid_file="$HOME/.config/zathura/xid"
# Open tabbed if necessary
if ! ps -e | grep 'zathura$'; then
[ $focus ] && num_wins=$(wmctrl -l | wc -l)
tabbed -cd -p -1 zathura "$1" -e 1>$xid_file &
if [ $focus ]; then
while [ $num_wins -eq $(wmctrl -l | wc -l) ]; do
sleep 0.0001
done
read xid < $xid_file
wmctrl -ir $xid -b add,maximized_vert,maximized_horz
fi
shift
fi
# Open the rest of the files into tabbed
if [ "$#" -gt 0 ]; then
read xid < $xid_file
zathura -e $xid "$@" &
if [ $focus ]; then
wmctrl -ir $xid -b add,above
wmctrl -ir $xid -b remove,above
fi
fi
The script uses:
- zathura as the document viewer.
- tabbed for your tabbed interface. Every subsequent file will be loaded as a new tab.
- ps, should work with all versions.
- wmctrl, for auto-focusing (and maximizing) the window. (OPTIONAL)
- wc, works with all versions. Needed for focusing window. (OPTIONAL)
There is only one option in this script:
focus
, which will manage the zathura window to pop up whenever it is opened.
Installation[edit]
Copy the above code into a zathura.sh
script (or whatever you want) in either a $PATH
directory or in your $VIFM/scripts
directory.
Then go into your vifm rc file and assign the file type:
filextype *.pdf,*.djvu,*.epub zathura.sh %f &
For Other Kinds of Documents[edit]
For other kinds of documents, you can convert them to a pdf using unoconv.
Paste this code into a shell script called zadocx.sh
for viewing files of the .docx
format.
#!/bin/bash
while [ "$#" -gt 0 ]; do
pdf_name=$(basename -s .docx "$1").pdf
unoconv "$1"
rm "$1"
zathura.sh "$pdf_name"
shift
done
NOTE This script will delete your docx file, so you may want to back it up or remove the 'rm' line |
Then assign the file type in your rc file in the same manner as the last one.