Created
May 31, 2012 17:32
-
-
Save Gen2ly/2844935 to your computer and use it in GitHub Desktop.
Copy common, other, and their previous password to clipboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copy common, other, and their previous password to clipboard | |
stpw_dir=$HOME # directory containing password files | |
stpw_dro=$stpw_dir/.sitepass-old # directory containing old passwords | |
stpw_fc=$stpw_dir/.sitepass-com.txt # filename containing common passwd | |
stpw_fo=$stpw_dir/.sitepass-oth.txt # filename containing other passwd | |
stpw_fC=$(ls -1 $stpw_dro/.sitepass-com* | tail -n 1) #filename of previous comm | |
stpw_fO=$(ls -1 $stpw_dro/.sitepass-oth* | tail -n 1) #filename of previous othe | |
# Required program(s) | |
req_progs=(xclip) | |
for p in ${req_progs[@]}; do | |
hash "$p" 2>&- || \ | |
{ echo >&2 " Required program \"$p\" not installed."; exit 1; } | |
done | |
# Display usage if no parameters given | |
scrp_help () { | |
echo " ${0##*/} <c,o,co,oo> - copy common, other, and previous passwords to clipb. | |
c | common - common | |
o | other - other | |
cp | comprv - common previous | |
op | othprv - other previous | |
x | clear - clear password from clipboard" | |
} | |
case $1 in | |
c | common ) # Copy password to Xorg server clipboard | |
xclip -in -selection c "$stpw_fc" && \ | |
echo " Copied password (common) to clipboard." | |
;; | |
o | other ) # Copy password to Xorg server clipboard | |
xclip -in -selection c "$stpw_fo" && \ | |
echo " Copied password (other) to clipboard." | |
;; | |
cp | comprv ) # Copy password to Xorg server clipboard | |
xclip -in -selection c "$stpw_fC" && \ | |
echo " Copied password (common previous) to clipboard." | |
;; | |
op | othprv ) # Copy password to Xorg server clipboard | |
xclip -in -selection c "$stpw_fO" && \ | |
echo " Copied password (other previous) to clipboard." | |
;; | |
x | clear ) echo "" | xclip -in -selection c | |
echo " Cleared password from Xorg server clipboard" | |
;; | |
* ) # Display usage if no or wrong parameter given | |
scrp_help | |
exit | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment