Fixed i3lock script to only run once at the same time.

clean_emacs
Tuan-Dat Tran 2018-09-12 22:42:41 +02:00
parent c6f99af469
commit 64f483c954
No known key found for this signature in database
GPG Key ID: 0DA1B0B23302CA72
4 changed files with 81 additions and 44 deletions

View File

@ -5,5 +5,5 @@ map f console scout -ftsea%space
map gg console mkdir%space map gg console mkdir%space
map np shell cp -r ~/Templates/LaTeX/Protokoll $(date +%g.%m.%%d) map np shell cp -r ~/Templates/LaTeX/Protokoll $(date +%g.%m.%%d)
map ny shell cp %f ../Protokoll_$(echo $(basename $(pwd)) | awk '{gsub("\\.","-");print}' $2).pdf map ny shell cp %f ../Protokoll_$(echo $(basename $(pwd)) | awk '{gsub("\\.","-");print}' $2).pdf
map nr shell cp ~/Templates/LaTeX/Invoice/invoice.tex Gefeba_Engineering_-_Rechnung_$(date +%g.%m)_-Elektro-1.tex map nr shell cp ~/Templates/LaTeX/Invoice/invoice.tex Gefeba_Engineering_-_Rechnung_$(date +%g.%m)_-Elektro.tex

View File

@ -1 +0,0 @@
0

View File

@ -9,7 +9,7 @@ def screenshot():
os.system('scrot /tmp/i3lock.png') os.system('scrot /tmp/i3lock.png')
print('Screenshot: {}'.format(time.time() - ss_time)) print('Screenshot: {}'.format(time.time() - ss_time))
def pixelate(): def pixelate():
pxl_time = time.time() pxl_time = time.time()
pixelSize = 12 pixelSize = 12
@ -20,9 +20,9 @@ def pixelate():
image = image.resize((int(image_x / pixelSize), int(image_y / pixelSize)), Image.NEAREST) image = image.resize((int(image_x / pixelSize), int(image_y / pixelSize)), Image.NEAREST)
image_x, image_y = image.size image_x, image_y = image.size
image = image.resize((image_x * pixelSize, image_y * pixelSize), image = image.resize((image_x * pixelSize, image_y * pixelSize),
Image.NEAREST) Image.NEAREST)
image.save('/tmp/i3lock.png') image.save('/tmp/i3lock.png')
print('pixelate: {}'.format(time.time() - pxl_time)) print('pixelate: {}'.format(time.time() - pxl_time))
@ -82,7 +82,7 @@ def lock_config():
# Color of the circle if wrong | Color: transparent # Color of the circle if wrong | Color: transparent
lock_wrong_color = '--insidewrongcolor 00000000 ' lock_wrong_color = '--insidewrongcolor 00000000 '
indicator_inner = "{} {} {}".format(lock_rest_color, lock_wrong_color, indicator_inner = "{} {} {}".format(lock_rest_color, lock_wrong_color,
lock_ver_color) lock_ver_color)
# indicator_outer_ring # indicator_outer_ring
# Default Color of the ring | Color: torquoise # Default Color of the ring | Color: torquoise
@ -111,13 +111,13 @@ def lock_config():
lock_radius = '--radius {}'.format(ring_size) lock_radius = '--radius {}'.format(ring_size)
lock_stats = '{} {}'.format(lock_pos, lock_radius) lock_stats = '{} {}'.format(lock_pos, lock_radius)
indicator_outer_ring = "{} {} {} {} {} {} {} {}".format(lock_ring, indicator_outer_ring = "{} {} {} {} {} {} {} {}".format(lock_ring,
lock_ring_w, lock_ring_w,
lock_ring_v, lock_ring_v,
lock_press, lock_press,
lock_del, lock_del,
lock_sep_color, lock_sep_color,
lock_stats, lock_stats,
lock_texts) lock_texts)
# done # done
indicator = "{} {}".format(indicator_inner, indicator_outer_ring) indicator = "{} {}".format(indicator_inner, indicator_outer_ring)
@ -126,7 +126,7 @@ def lock_config():
print('lock: {}'.format(time.time() - lock_time)) print('lock: {}'.format(time.time() - lock_time))
return "{} {} {} {} {}".format(lock_core, clock, datetime, indicator, return "{} {} {} {} {}".format(lock_core, clock, datetime, indicator,
lock_pic) lock_pic)
def lock(): def lock():
@ -135,6 +135,40 @@ def lock():
os.system(command) os.system(command)
def proc_exists(proc_name):
proc_check = time.time()
this_proc = "i3lock.py"
proc_path = '/proc'
proc = next(os.walk('{}/'.format(proc_path)))[1]
counter = 0
for process in proc:
counter+=1
cmdline_path = '{}/{}/cmdline'.format(proc_path,process)
try:
with open(cmdline_path, 'r') as cmd:
proc_content = cmd.readline()
proc_content = '{}: {}'.format(counter, proc_content)
if proc_content:
if proc_name in proc_content:
# print(proc_name)
# print(proc_content)
# print(proc_name in proc_content)
if 'xss-lock' not in proc_content:
# print('xss-lock' not in proc_content)
if this_proc not in proc_content:
# print(this_proc not in proc_content)
print('Process Exists: {}'.format(time.time() - proc_check))
return True
except FileNotFoundError:
pass
print('Process Exists: {}'.format(time.time() - proc_check))
return False
def is_running():
return proc_exists("i3lock")
def log(start_time): def log(start_time):
write_mode = '' write_mode = ''
@ -151,11 +185,11 @@ def log(start_time):
f.write("[{}] {} seconds runtime.\n".format(time.asctime(), program_duration)) f.write("[{}] {} seconds runtime.\n".format(time.asctime(), program_duration))
f.close() f.close()
if __name__ == '__main__': if __name__ == '__main__':
if not is_running():
start_time = time.time() start_time = time.time()
screenshot() screenshot()
pixelate() pixelate()
lock() lock()
log(start_time) log(start_time)

View File

@ -27,43 +27,47 @@ POWERLEVEL9k_SHORTEN_STRATEGY="trunctuate_middle"
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
# Alias # Alias
alias matrix="cmatrix"
alias df="df -h"
alias mkvirtenv="python -m virtualenv --system-site-packages"
alias e="emacsclient -t"
alias ek="pkill emacs"
alias ej="emacs --daemon"
alias nyan="nyancat"
alias rm="rm -I"
alias -s tex=vim
alias -s cpp=vim alias -s cpp=vim
alias -s org=vim alias -s org=vim
alias diff="diff -s" alias -s tex=vim
alias stunden="et $HOME/Nextcloud/Arbeit/Stunden/Stundenzettel.xlsx &; disown %1;"
alias budget="emacs -nw $HOME/Nextcloud/orgs/Budget/MyBudget.ledger" alias budget="emacs -nw $HOME/Nextcloud/orgs/Budget/MyBudget.ledger"
alias vudget="vim $HOME/Nextcloud/orgs/Budget/MyBudget.ledger" alias df="df -h"
alias diff="diff -s"
alias e="emacsclient -t"
alias ej="emacs --daemon"
alias ek="pkill emacs"
alias erc='emacs -nw ~/.emacs.d/config.org'
alias matrix="cmatrix"
alias mkvirtenv="python -m virtualenv --system-site-packages"
alias mp3='youtube-dl --embed-thumbnail -x --audio-format mp3 -o "./%(title)s.%(ext)s"'
alias nyan="nyancat"
alias pastebin='vim ~/Nextcloud/pastebin.txt'
alias q="exit" alias q="exit"
alias ranger='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"' alias ranger='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"'
alias rm="rm -I"
alias steam='steam' alias steam='steam'
alias vrc='vim ~/.vimrc' alias stunden="et $HOME/Nextcloud/Arbeit/Stunden/Stundenzettel.xlsx &; disown %1;"
alias erc='emacs -nw ~/.emacs.d/config.org'
alias mp3='youtube-dl -x --audio-format mp3 -o "./%(title)s.%(ext)s"'
alias zrc='vim ~/.zshrc'
alias vpn_eu='sudo openvpn --config Downloads/AirVPN_Europe_UDP-443.ovpn' alias vpn_eu='sudo openvpn --config Downloads/AirVPN_Europe_UDP-443.ovpn'
alias vpn_us='sudo openvpn --config Downloads/AirVPN_America_UDP-443.ovpn' alias vpn_us='sudo openvpn --config Downloads/AirVPN_America_UDP-443.ovpn'
alias vrc='vim ~/.vimrc'
alias vudget="vim $HOME/Nextcloud/orgs/Budget/MyBudget.ledger"
alias watch='watch --color'
alias zrc='vim ~/.zshrc'
source $ZSH/oh-my-zsh.sh source $ZSH/oh-my-zsh.sh
# Variables # Variables
export TERM="xterm-256color" # in case you are using urxvt, to bypass an error during sshing
export GPG_TTY=$(tty)
export LC_ALL=en_GB.UTF-8
PATH=$PATH:$HOME/.local/bin:/usr/lib/jvm/java-10-openjdk/bin PATH=$PATH:$HOME/.local/bin:/usr/lib/jvm/java-10-openjdk/bin
export EDITOR='vim'
export DEFAULT_EDITOR=$EDITOR export DEFAULT_EDITOR=$EDITOR
export EDITOR='vim'
export GOPATH="$HOME/workspace/go/"
export GPG_TTY=$(tty)
export HIGHLIGHT_DATADIR="~/.config/highlight/"
export LC_ALL=en_GB.UTF-8
export STEAM_FRAME_FORCE_CLOSE=1
export TERM="xterm-256color" # in case you are using urxvt, to bypass an error during sshing
export VISUAL=$EDITOR export VISUAL=$EDITOR
export VISUAL_EDITOR=$EDITOR export VISUAL_EDITOR=$EDITOR
export STEAM_FRAME_FORCE_CLOSE=1
export HIGHLIGHT_DATADIR="~/.config/highlight/"
export GOPATH="$HOME/workspace/go/"
# Functions # Functions