From 9b19480228d8421c3987a634a602012c953a993e Mon Sep 17 00:00:00 2001 From: neodarz Date: Thu, 5 Sep 2019 07:48:16 +0200 Subject: Add some scripts --- dotfiles/scripts/2gif.sh | 109 ++++++++++++++ dotfiles/scripts/AN2Linux.sh | 9 ++ dotfiles/scripts/bin-xfer | 36 +++++ dotfiles/scripts/cycle-workspace-multiscreen.py | 74 ++++++++++ dotfiles/scripts/cycle-workspace.py | 26 ++++ dotfiles/scripts/domainsTest.sh | 12 ++ dotfiles/scripts/dropshadow.sh | 29 ++++ dotfiles/scripts/fingerprint | 66 +++++++++ dotfiles/scripts/i3removesupportof.py | 56 ++++++++ dotfiles/scripts/internet-from_wifi_to_internet.sh | 21 +++ dotfiles/scripts/ip.sh | 11 ++ dotfiles/scripts/launch_rofi-pass.sh | 1 + dotfiles/scripts/lessfilter.sh | 20 +++ dotfiles/scripts/linux_system_error_list.py | 46 ++++++ dotfiles/scripts/linux_system_error_list.sh | 4 + dotfiles/scripts/mpvbg | 27 ++++ dotfiles/scripts/my-pinentry | 16 +++ dotfiles/scripts/notify | 1 + dotfiles/scripts/nullify | 2 + dotfiles/scripts/pyrnotify.py | 160 +++++++++++++++++++++ dotfiles/scripts/searx.sh | 3 + dotfiles/scripts/ssh.sh | 24 ++++ dotfiles/scripts/switch-workspace.py | 45 ++++++ dotfiles/scripts/switch_audio.sh | 16 +++ dotfiles/scripts/task | 28 ++++ dotfiles/scripts/tdone | 30 ++++ dotfiles/scripts/tm.sh | 49 +++++++ dotfiles/scripts/watch | 12 ++ dotfiles/scripts/weechat_notify.sh | 12 ++ dotfiles/scripts/what.sh | 42 ++++++ dotfiles/scripts/what_alias.sh | 56 ++++++++ dotfiles/scripts/what_command_help.sh | 40 ++++++ dotfiles/scripts/working.sh | 3 + dotfiles/scripts/working_tmux.yaml | 15 ++ dotfiles/scripts/write_on_disk.rb | 63 ++++++++ dotfiles/scripts/zsh_aliases_functions.sh | 6 + 36 files changed, 1170 insertions(+) create mode 100755 dotfiles/scripts/2gif.sh create mode 100755 dotfiles/scripts/AN2Linux.sh create mode 100755 dotfiles/scripts/bin-xfer create mode 100755 dotfiles/scripts/cycle-workspace-multiscreen.py create mode 100755 dotfiles/scripts/cycle-workspace.py create mode 100755 dotfiles/scripts/domainsTest.sh create mode 100755 dotfiles/scripts/dropshadow.sh create mode 100755 dotfiles/scripts/fingerprint create mode 100755 dotfiles/scripts/i3removesupportof.py create mode 100755 dotfiles/scripts/internet-from_wifi_to_internet.sh create mode 100755 dotfiles/scripts/ip.sh create mode 100755 dotfiles/scripts/launch_rofi-pass.sh create mode 100755 dotfiles/scripts/lessfilter.sh create mode 100755 dotfiles/scripts/linux_system_error_list.py create mode 100755 dotfiles/scripts/linux_system_error_list.sh create mode 100755 dotfiles/scripts/mpvbg create mode 100755 dotfiles/scripts/my-pinentry create mode 100755 dotfiles/scripts/notify create mode 100755 dotfiles/scripts/nullify create mode 100644 dotfiles/scripts/pyrnotify.py create mode 100755 dotfiles/scripts/searx.sh create mode 100755 dotfiles/scripts/ssh.sh create mode 100755 dotfiles/scripts/switch-workspace.py create mode 100755 dotfiles/scripts/switch_audio.sh create mode 100755 dotfiles/scripts/task create mode 100755 dotfiles/scripts/tdone create mode 100755 dotfiles/scripts/tm.sh create mode 100755 dotfiles/scripts/watch create mode 100755 dotfiles/scripts/weechat_notify.sh create mode 100755 dotfiles/scripts/what.sh create mode 100755 dotfiles/scripts/what_alias.sh create mode 100755 dotfiles/scripts/what_command_help.sh create mode 100755 dotfiles/scripts/working.sh create mode 100644 dotfiles/scripts/working_tmux.yaml create mode 100644 dotfiles/scripts/write_on_disk.rb create mode 100755 dotfiles/scripts/zsh_aliases_functions.sh (limited to 'dotfiles/scripts') diff --git a/dotfiles/scripts/2gif.sh b/dotfiles/scripts/2gif.sh new file mode 100755 index 0000000..ec325dc --- /dev/null +++ b/dotfiles/scripts/2gif.sh @@ -0,0 +1,109 @@ +#!/bin/sh + +# source: https://github.com/Drakirus/dotfiles/blob/master/bin/2gif + +$(ffmpeg --help 2> /dev/null > /dev/null) + +if [[ $? -ne 0 ]]; then + echo "ffmpeg is required!" + exit 1 +fi + +# default values +FPS=12 + +# read the options +TEMP=`getopt -o c:r:f:t:s:d:hl:: --long resolution:,fps:,start:,to:,duration:,help,loop:: -n $0 -- "$@"` +eval set -- "$TEMP" + +# extract options and their arguments into variables. +while true ; do + case "$1" in + -h|--help) + echo -e "Usage: $0 [options] \n" + echo "Options:" + echo " -h, --help Show this help" + echo " -r, --resolution Set the pixels wide (preserving the aspect ratio)" + echo " -f, --fps Set the gif frame rate" + echo " default 12" + echo " -s, --start Skip the first x seconds" + echo " -t, --to Capture to x seconds" + echo " -d, --duration Set the duration" + echo " -l, --loop Number of times to loop the output" + echo " default: no loop" + echo " -l output loop infinitely" + echo " -l10 output loop 10 times" + echo "Examples:" + echo " $0 input.mp4 out.gif" + echo " $0 input.mp4 out.gif -s"00:01" -d5 -r450" + echo " $0 input.mp4 out.gif -s"20:00" -d5 -l --fps30" + exit;; + -r|--resolution) + case "$2" in + "") shift 2 ;; + *) RESOLUTION="$2"; shift 2 ;; + esac ;; + -t|--to) + case "$2" in + "") shift 2 ;; + *) TO="-t $2"; shift 2 ;; + esac ;; + -l|--loop) + case "$2" in + "") LOOP="-loop=0" ; shift 2 ;; + *) LOOP="-loop=$2" ; shift 2 ;; + esac ;; + -f|--fps) + case "$2" in + "") shift 2 ;; + *) FPS="$2"; shift 2 ;; + esac ;; + -s|--start) + case "$2" in + "") shift 2 ;; + *) START="-ss $2"; shift 2 ;; + esac ;; + -d|--duration) + case "$2" in + "") shift 2 ;; + *) DURATION="-t $2"; shift 2 ;; + esac ;; + --) shift ; break ;; + *) echo "Internal error!" ; exit 1 ;; + esac +done + +if [[ "$#" -ne 2 && "$#" -ne 1 ]]; then + echo -e "Usage: $0 [options] \n" + echo -e "Illegal number of parameters or parameters.\nFor more informations:\n $0 --help " + exit 1 +fi + +OUTPUT="$2" + +if [[ "$#" -eq 1 ]]; then + filename=$(basename "$1") + filename="${filename%.*}.gif" + OUTPUT=$filename +fi + +if [[ "$RESOLUTION" -eq "" ]]; then + eval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=width "$1") + RESOLUTION=${streams_stream_0_width} +fi + +palette=$(mktemp /tmp/palette_XXXX.png) + +filters="fps=$FPS,scale=$RESOLUTION:-1:flags=lanczos" + +# echo $filters + +# http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html#usage + +# create global color palette +ffmpeg -v warning $START $TO $DURATION -i "$1" -vf "$filters,palettegen" -y "$palette" + +# create GIF +ffmpeg -v warning $START $TO $DURATION -i "$1" -i "$palette" -lavfi "$filters [x]; [x][1:v] paletteuse" -y "$OUTPUT" + +rm $palette diff --git a/dotfiles/scripts/AN2Linux.sh b/dotfiles/scripts/AN2Linux.sh new file mode 100755 index 0000000..263f932 --- /dev/null +++ b/dotfiles/scripts/AN2Linux.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +if [[ $1 && $2 && $3 ]];then + ssh-add -l |grep -q `ssh-keygen -lf $1 | awk '{print $2}'` || ssh-add $1 + ssh root@$2 "/root/AN2Linux.sh start $(\ip addr show $3 | grep "inet " | cut -d'/' -f1 | awk '{print $2}')"; an2linuxserver.py; ssh root@$2 "/root/AN2Linux.sh stop $(\ip addr show $3 | grep "inet " | cut -d'/' -f1 | awk '{print $2}')"; +else + echo "Usage:" + echo " $0 " +fi diff --git a/dotfiles/scripts/bin-xfer b/dotfiles/scripts/bin-xfer new file mode 100755 index 0000000..e2ccce5 --- /dev/null +++ b/dotfiles/scripts/bin-xfer @@ -0,0 +1,36 @@ +#!/bin/sh +INFILE=/dev/null +OUTFILE=/dev/null + +while [ $# -gt 0 ]; do + case "$1" in + -i) + shift + INFILE="$1" + ;; + -o) + shift + OUTFILE="$1" + ;; + -h|--help) + echo "$0 -i infile -o outfile" + ;; + *) + INFILE="$1" + esac + shift +done +cat << EOF +binary-xfer utility for minicom +Sending file ${INFILE} to ${OUTFILE} +EOF + +/usr/bin/pv --force -i 0.25 -B 128 ${INFILE} 2>&1 > ${OUTFILE} +# Use the line below if you don't have pv! + +# /bin/cat ${INFILE} > ${OUTFILE} +cat << EOF + +File transfer complete +EOF +sleep 1 diff --git a/dotfiles/scripts/cycle-workspace-multiscreen.py b/dotfiles/scripts/cycle-workspace-multiscreen.py new file mode 100755 index 0000000..e5e70ef --- /dev/null +++ b/dotfiles/scripts/cycle-workspace-multiscreen.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python + +# cycle-workspace-multiscreen +# Moves the currently active workspace to the left/right/top/bottom active +# display. +# Depends on i3-py (`pip install i3-py`) +# Because workspace name are fixed to a display, just rename workspace can +# change workspace to another display. +# So for the moment this script is tested and work if workspaces are fixed +# to a display. + +import i3 +import sys + +# figure out what is on, and what is currently on your screen. +workspace_origin = list(filter(lambda s: s['focused'], i3.get_workspaces()))[0] +outputs = list(filter(lambda s: s['active'], i3.get_outputs())) +output_origin = "" + +for output in outputs: + if output['current_workspace'] == workspace_origin['name']: + output_origin = output + +output_destination = workspace_origin + +if sys.argv[1] == "right": + output_origin_x = output_origin['rect']['x'] + output_origin_width = output_origin['rect']['width'] + next_workspace_start = output_origin_x + output_origin_width + for output in outputs: + if next_workspace_start == output['rect']['x']: + output_destination = output + +if sys.argv[1] == "left": + output_origin_x = output_origin['rect']['x'] + output_origin_width = output_origin['rect']['width'] + next_workspace_start = output_origin_x - output_origin_width + for output in outputs: + next_workspace_start = output_origin_x - output['rect']['width'] + if next_workspace_start == output['rect']['x']: + output_destination = output + +if sys.argv[1] == "bottom": + output_origin_y = output_origin['rect']['y'] + output_origin_height = output_origin['rect']['height'] + next_workspace_start = output_origin_y + output_origin_height + for output in outputs: + if next_workspace_start == output['rect']['y']: + output_destination = output + +if sys.argv[1] == "top": + output_origin_y = output_origin['rect']['y'] + output_origin_height = output_origin['rect']['height'] + next_workspace_start = output_origin_y - output_origin_height + for output in outputs: + next_workspace_start=output_origin_y - output['rect']['height'] + if next_workspace_start == output['rect']['y']: + output_destination = output + +if (output_destination != workspace_origin): + # Move origin workspace to the correct screen + i3.command('move', 'workspace to output '+output_destination['name']) + # Rename origin workspace to temporary workspace of the screen destination + i3.command('rename', 'workspace '+str(workspace_origin['name'])+' to a_fucking_workspace') + # Change focus to the workspace destination + i3.workspace(output_destination['current_workspace']) + # Move destination workspace to the correct screen + i3.command('move', 'workspace to output '+workspace_origin['output']) + # Rename workspace destination to the origin workspace + i3.command('rename', 'workspace '+output_destination['current_workspace']+' to '+str(workspace_origin['name'])) + # Rename temporary workspace to workspace destination + i3.command('rename', 'workspace a_fucking_workspace to '+output_destination['current_workspace']) + # Change focus the workspace destination + i3.workspace(output_destination['current_workspace']) diff --git a/dotfiles/scripts/cycle-workspace.py b/dotfiles/scripts/cycle-workspace.py new file mode 100755 index 0000000..7f176db --- /dev/null +++ b/dotfiles/scripts/cycle-workspace.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +#https://gist.github.com/97-109-107/b70356670ae8309ffb4f + +import i3 + +outputs = i3.get_outputs() +workspaces = i3.get_workspaces() + +# figure out what is on, and what is currently on your screen. +workspace = list(filter(lambda s: s['focused']==True, workspaces)) +output = list(filter(lambda s: s['active']==True, outputs)) + +# figure out the other workspace name +other_workspace = list(filter(lambda s: s['name']!=workspace[0]['output'], output)) + + + +# send current to the no-active one +i3.command('move', 'workspace to output '+other_workspace[0]['name']) + + + +#print(str(list(filter(lambda s: s['active']==True, workspaces)))) + +i3.command('workspace', other_workspace[0]['current_workspace']) +i3.command('move', 'workspace to output '+workspace[0]['output']) diff --git a/dotfiles/scripts/domainsTest.sh b/dotfiles/scripts/domainsTest.sh new file mode 100755 index 0000000..2b3151a --- /dev/null +++ b/dotfiles/scripts/domainsTest.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Program name: pingall.sh +date +cat domains.txt | while read output +do + ping -c 1 "$output" &> /dev/null + if [ $? -eq 0 ]; then + echo "node $output is up" + else + echo "node $output is down" + fi +done diff --git a/dotfiles/scripts/dropshadow.sh b/dotfiles/scripts/dropshadow.sh new file mode 100755 index 0000000..4e70f82 --- /dev/null +++ b/dotfiles/scripts/dropshadow.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# NAME: dropshadow.sh +# VERSION: +# AUTHOR: (c) 2013 Glutanimate +# DESCRIPTION: - adds transparent dropshadow to images (e.g. screenshots) +# - moves them to predefined screenshot folder +# FEATURES: +# DEPENDENCIES: imagemagick suite +# +# LICENSE: MIT license (http://opensource.org/licenses/MIT) +# +# NOTICE: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +# OR OTHER DEALINGS IN THE SOFTWARE. +# +# +# USAGE: dropshadow.sh + +SCREENSHOTFOLDER="$HOME/Screenshots" + + +FILE="${1}" +FILENAME="${FILE##*/}" +FILEBASE="${FILENAME%.*}" + +convert "${FILE}" \( +clone -background black -shadow 80x20+0+15 \) +swap -background transparent -layers merge +repage "$SCREENSHOTFOLDER/${FILEBASE}.png" diff --git a/dotfiles/scripts/fingerprint b/dotfiles/scripts/fingerprint new file mode 100755 index 0000000..8e15a98 --- /dev/null +++ b/dotfiles/scripts/fingerprint @@ -0,0 +1,66 @@ +#!/usr/bin/env ruby + +# Usage exemple: ./fingerprint twitter.com api.twitter.com ton.twitter.com twitter.com tweetdeck.twitter.com userstream.twitter.com abs.twitter.com psb.twimg.com ton.twing.com video.twimg.com 2> /dev/null +# List of figerprint by domain name + +require 'resolv' +require 'openssl' +require 'set' + +hosts = Set.new +ips = Set.new +certs = Set.new +subjects = Set.new +cas = Set.new +fps = Set.new +keys = Set.new + +resolver = Resolv::DNS.new +ARGV.each do |host| + $stderr.puts host + hosts << host + resolver.each_address(host) do |ip| + ip = ip.to_s + ips << ip + $stderr.puts " #{ip}" + tcp_client = TCPSocket.new ip, 443 + ssl_client = OpenSSL::SSL::SSLSocket.new tcp_client + ssl_client.hostname = host + ssl_client.connect + cert = ssl_client.peer_cert + certs << cert + + subject = cert.subject + subjects << subject + $stderr.puts " CN=#{subject}" + + ca = cert.issuer + cas << ca + $stderr.puts " CA=#{ca}" + + fp = OpenSSL::Digest::SHA256.hexdigest cert.to_der + fps << fp + $stderr.puts " fp=#{fp}" + + key = ::OpenSSL::Digest::SHA256.hexdigest cert.public_key.to_der + keys << key + $stderr.puts " key=#{key}" + + ssl_client.close + end +end + +puts "#{hosts.size} hosts" +hosts.sort.each { |l| puts " #{l}"} +puts "#{ips.size} IPs" +ips.sort.each { |l| puts " #{l}"} +puts "#{fps.size} certificates" +fps.sort.each { |l| puts " #{l}"} +puts "#{cas.size} CAs" +cas.sort.each { |l| puts " #{l}"} +puts "#{subjects.size} subjects" +subjects.sort.each { |l| puts " #{l}"} +puts "#{keys.size} keys" +keys.sort.each { |l| puts " #{l}"} + + diff --git a/dotfiles/scripts/i3removesupportof.py b/dotfiles/scripts/i3removesupportof.py new file mode 100755 index 0000000..6cbc877 --- /dev/null +++ b/dotfiles/scripts/i3removesupportof.py @@ -0,0 +1,56 @@ +#/bin/python + +import re, sys, os + +key_to_rm=str(sys.argv[1]) +config_file=os.path.expanduser("~/.config/i3/config") + +oneline_conf_file = "" + +conf_file_input = open(config_file, 'r') + +for line in conf_file_input: + line = re.sub("^#{1}\.", "", line) + oneline_conf_file = oneline_conf_file + line + +conf_file_input.close() + + +# add key +block_conf_found = re.search(r"#{1}"+key_to_rm+".*#{1}"+key_to_rm+".", oneline_conf_file, re.DOTALL) + +if block_conf_found != None: + + block_conf_found_splited = block_conf_found.group(0).splitlines() + + oneline_final_data = "" + line_parsed=0 + comment_this_line=0 + end_key=0 + for line in block_conf_found_splited: + if re.search("^#{1}"+key_to_rm+"$", line): + comment_this_line=1 + elif re.search("^#{1}"+key_to_rm+".$", line): + end_key=1 + comment_this_line=0 + if comment_this_line == 1: + oneline_final_data = oneline_final_data + "#." + line + elif end_key == 1: + oneline_final_data = oneline_final_data + "#." + line + end_key = 0 + else: + oneline_final_data = oneline_final_data + line + if line_parsed != len(block_conf_found_splited)-1: + oneline_final_data = oneline_final_data + "\n" + line_parsed = line_parsed + 1 + + + oneline_new_conf_file = re.sub(r"#"+key_to_rm+".*#"+key_to_rm+".", oneline_final_data, oneline_conf_file, flags=re.DOTALL) + + confOutput = open(config_file, 'w') + + confOutput.write(oneline_new_conf_file) + + confOutput.close() +else: + print("Sorry the keymap '"+str(sys.argv[1])+"' is not in this conf file, use 'fr' or 'bepo'.\nBetween, this script is used to remove a keymap support for i3wm.\nUsage:\n "+sys.argv[0]+" fr") diff --git a/dotfiles/scripts/internet-from_wifi_to_internet.sh b/dotfiles/scripts/internet-from_wifi_to_internet.sh new file mode 100755 index 0000000..83d9b2b --- /dev/null +++ b/dotfiles/scripts/internet-from_wifi_to_internet.sh @@ -0,0 +1,21 @@ +#!/bin/sh +#sudo ip addr add 192.168.123.102/24 dev enp3s0 +#sudo ip route add default via 192.168.123.100 dev enp3s0 + +if [[ $1 == "start" ]]; then + /usr/lib/netctl/network start wlp2s0-Livebox-C1D0 + ip addr add 192.168.123.100/24 dev enp3s0 + sysctl net.ipv4.ip_forward=1 + iptables -t nat -A POSTROUTING -o wlp2s0 -j MASQUERADE + iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT + iptables -A FORWARD -i enp3s0 -o wlp3s0 -j ACCEPT +elif [[ $1 == "stop" ]]; then + /usr/lib/netctl/network stop wlp2s0-Livebox-C1D0 + iptables -t nat -D POSTROUTING -o wlp2s0 -j MASQUERADE + iptables -D FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT + iptables -D FORWARD -i enp3s0 -o wlp3s0 -j ACCEPT + ip addr del 192.168.123.100/24 dev enp3s0 + sysctl net.ipv4.ip_forward=0 +else + echo "error" +fi diff --git a/dotfiles/scripts/ip.sh b/dotfiles/scripts/ip.sh new file mode 100755 index 0000000..547c451 --- /dev/null +++ b/dotfiles/scripts/ip.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# sudo apt install dnsutils jq && sudo -H pip3 install speedtest-cli + +myip=$(dig +short myip.opendns.com @resolver1.opendns.com) +geoip=$(curl -s ipinfo.io/"$myip" | jq -r '[.country, .city] | join(", ")') + +echo "$myip ($geoip)" +speedtest-cli --simple --secure + +exit 0 + diff --git a/dotfiles/scripts/launch_rofi-pass.sh b/dotfiles/scripts/launch_rofi-pass.sh new file mode 100755 index 0000000..87654ce --- /dev/null +++ b/dotfiles/scripts/launch_rofi-pass.sh @@ -0,0 +1 @@ +PINENTRY_USER_DATA="gtk" exec rofi-pass diff --git a/dotfiles/scripts/lessfilter.sh b/dotfiles/scripts/lessfilter.sh new file mode 100755 index 0000000..d85c217 --- /dev/null +++ b/dotfiles/scripts/lessfilter.sh @@ -0,0 +1,20 @@ +#!/bin/sh +case "$1" in + *.awk|*.groff|*.java|*.js|*.m4|*.php|*.pl|*.pm|*.pod|*.sh|\ + *.ad[asb]|*.asm|*.inc|*.[ch]|*.[ch]pp|*.[ch]xx|*.cc|*.hh|\ + *.lsp|*.l|*.pas|*.p|*.xml|*.xps|*.xsl|*.axp|*.ppd|*.pov|\ + *.diff|*.patch|*.py|*.rb|*.sql|*.ebuild|*.eclass) + pygmentize -f 256 "$1";; + .bashrc|.bash_aliases|.bash_environment) + pygmentize -f 256 -l sh "$1" + ;; + *) + grep "#\!/bin/bash" "$1" > /dev/null + if [ "$?" -eq "0" ]; then + pygmentize -f 256 -l sh "$1" + else + exit 1 + fi + esac + +exit 0 diff --git a/dotfiles/scripts/linux_system_error_list.py b/dotfiles/scripts/linux_system_error_list.py new file mode 100755 index 0000000..ee1a7a6 --- /dev/null +++ b/dotfiles/scripts/linux_system_error_list.py @@ -0,0 +1,46 @@ +#!/bin/python + +import re, sys +from terminaltables import DoubleTable + +data = [] +data.append(['Error', 'Code', 'Comment']) + +def get_content(file): + + with open(file) as f: + content = f.readlines() + + content = [x.strip() for x in content] + + for line in content: + if re.search('define',line): + line = re.sub('#define\t', '', line) + line = re.sub('(?m)^#define .*\n?', '', line) + line = re.sub('\t\t', '\t', line) + line = re.sub('(/\*|\*/)', '', line) + if line != '': + data.append(re.split(r'\t',line)) + +get_content("/usr/include/asm-generic/errno-base.h") +get_content("/usr/include/asm-generic/errno.h") + +if len(sys.argv) == 2 and sys.argv[1] == "list": + table = DoubleTable(data, "Error code") + table.justify_columns = {0: 'right', 1: 'center', 2: 'left'} + print(table.table) +elif (len(sys.argv) == 2 or len(sys.argv) == 3) and sys.argv[1] == "search": + if len(sys.argv) == 3: + data_searched = [] + data_searched.append(['Error', 'Code', 'Comment']) + for line in data: + if re.search(sys.argv[2],str(line)): + data_searched.append(line) + table = DoubleTable(data_searched, "Error code") + table.justify_columns = {0: 'right', 1: 'center', 2: 'left'} + print(table.table) + else: + print("search # You can send regex following re.search python function") +else: + print("search # You can send regex following re.search python function") + print("list # Return list of all error from errno.h and errno-base.h") diff --git a/dotfiles/scripts/linux_system_error_list.sh b/dotfiles/scripts/linux_system_error_list.sh new file mode 100755 index 0000000..4b980d7 --- /dev/null +++ b/dotfiles/scripts/linux_system_error_list.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +cat /usr/include/asm-generic/errno-base.h +cat /usr/include/asm-generic/errno.h diff --git a/dotfiles/scripts/mpvbg b/dotfiles/scripts/mpvbg new file mode 100755 index 0000000..5afba5c --- /dev/null +++ b/dotfiles/scripts/mpvbg @@ -0,0 +1,27 @@ +#!/bin/bash +# +# http://github.com/mitchweaver/bin +# +# play a video on the root window +# +# Multi screen mode by neodarz + +[ -f "$1" ] || exit 1 + +pkill -9 xwinwrap + +readarray -t screen_connected < <(xrandr | grep " connected") +nb_screen_connected=${#screen_connected[@]} +for (( num_screen=0; num_screen<$nb_screen_connected; num_screen++)); do + screen_geo=$(echo ${screen_connected[num_screen]} | awk '{ print $3 }') + + xwin="xwinwrap -ni -fdt -sh rectangle -un -b -nf -ov -g $screen_geo -- " + + mpv="mpv --wid WID --no-config --keepaspect=no --loop \ + --no-border --vd-lavc-fast --x11-bypass-compositor=no \ + --gapless-audio=yes --vo=xv --hwdec=auto --really-quiet \ + --name=mpvbg" + + $xwin $mpv "$1" > /dev/null 2>&1 & + echo -n $! > ${HOME}/.cache/mpvbg-$num_screen.pid +done diff --git a/dotfiles/scripts/my-pinentry b/dotfiles/scripts/my-pinentry new file mode 100755 index 0000000..b46687e --- /dev/null +++ b/dotfiles/scripts/my-pinentry @@ -0,0 +1,16 @@ +#!/bin/bash +# choose pinentry depending on PINENTRY_USER_DATA +# requires pinentry-curses and pinentry-gtk2 +# this *only works* with gpg 2 +# see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=802020 + +case $PINENTRY_USER_DATA in +gtk) + exec /usr/bin/pinentry-gtk-2 "$@" + ;; +none) + exit 1 # do not ask for passphrase + ;; +*) + exec /usr/bin/pinentry-curses "$@" +esac diff --git a/dotfiles/scripts/notify b/dotfiles/scripts/notify new file mode 100755 index 0000000..6445914 --- /dev/null +++ b/dotfiles/scripts/notify @@ -0,0 +1 @@ +$@ ; twmnc -t "$1" -c "Job end !" diff --git a/dotfiles/scripts/nullify b/dotfiles/scripts/nullify new file mode 100755 index 0000000..212c88d --- /dev/null +++ b/dotfiles/scripts/nullify @@ -0,0 +1,2 @@ +#!/bin/sh +"$@" &>/dev/null diff --git a/dotfiles/scripts/pyrnotify.py b/dotfiles/scripts/pyrnotify.py new file mode 100644 index 0000000..53e9c0e --- /dev/null +++ b/dotfiles/scripts/pyrnotify.py @@ -0,0 +1,160 @@ +# -*- coding: utf-8 -*- +# ex:sw=4 ts=4:ai: +# +# Copyright (c) 2012 by Krister Svanlund +# based on tcl version: +# Remote Notification Script v1.1 +# by Gotisch +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# Example usage when Weechat is running on a remote PC and you want +# want to use port 4321 for the connection. +# +# On the "client" (where the notifications will end up), host is +# the remote host where weechat is running: +# python2 location/of/pyrnotify.py 4321 & ssh -R 4321:localhost:4321 username@host +# You can have a second argument to specified the time to display the notification +# python2 location/of/pyrnotify.py 4321 2000 & ssh -R 4321:localhost:4321 username@host +# Important to remember is that you should probably setup the +# connection with public key encryption and use something like +# autossh to do this in the background. +# +# In weechat: +# /python load pyrnotify.py +# and set the port +# /set plugins.var.python.pyrnotify.port 4321 +# +# It is also possible to set which host pyrnotify shall connect to, +# this is not recommended. Using a ssh port-forward is much safer +# and doesn't require any ports but ssh to be open. + +# ChangeLog: +# +# 2014-05-10: Change hook_print callback argument type of displayed/highlight +# (WeeChat >= 1.0) +# 2012-06-19: Added simple escaping to the title and body strings for +# the script to handle trailing backslashes. + +try: + import weechat as w + in_weechat = True +except ImportError as e: + in_weechat = False + +import os, sys, re +import socket +import subprocess +import shlex + +SCRIPT_NAME = "pyrnotify" +SCRIPT_AUTHOR = "Krister Svanlund " +SCRIPT_VERSION = "1.0" +SCRIPT_LICENSE = "GPL3" +SCRIPT_DESC = "Send remote notifications over SSH" + +def escape(s): + return re.sub(r'([\\"\'])', r'\\\1', s) + +def run_notify(icon, nick,chan,message): + host = w.config_get_plugin('host') + try: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((host, int(w.config_get_plugin('port')))) + s.send("normal %s \"%s to %s\" \"%s\"" % (icon, nick, escape(chan), escape(message))) + s.close() + except Exception as e: + w.prnt("", "Could not send notification: %s" % str(e)) + +def on_msg(*a): + if len(a) == 8: + data, buffer, timestamp, tags, displayed, highlight, sender, message = a + if data == "private" or int(highlight): + if data == "private" and w.config_get_plugin('pm-icon'): + icon = w.config_get_plugin('pm-icon') + else: + icon = w.config_get_plugin('icon') + buffer = "me" if data == "private" else w.buffer_get_string(buffer, "short_name") + run_notify(icon, sender, buffer, message) + #w.prnt("", str(a)) + return w.WEECHAT_RC_OK + +def weechat_script(): + settings = {'host' : "localhost", + 'port' : "4321", + 'icon' : "utilities-terminal", + 'pm-icon' : "emblem-favorite"} + if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""): + for (kw, v) in settings.items(): + if not w.config_get_plugin(kw): + w.config_set_plugin(kw, v) + w.hook_print("", "notify_message", "", 1, "on_msg", "") + w.hook_print("", "notify_private", "", 1, "on_msg", "private") + w.hook_print("", "notify_highlight", "", 1, "on_msg", "") # Not sure if this is needed + + + + + + +###################################### +## This is where the client starts, except for the global if-check nothing below this line is +## supposed to be executed in weechat, instead it runs when the script is executed from +## commandline. + +def accept_connections(s, timeout=None): + conn, addr = s.accept() + try: + data = "" + d = conn.recv(1024) + while d: + data += d + d = conn.recv(1024) + finally: + conn.close() + if data: + try: + urgency, icon, title, body = shlex.split(data) + if timeout: + #subprocess.call(["/usr/bin/twmnc", "-t", timeout, "-u", urgency, "-c", "IRC", "-i", icon, escape(title), escape(body)]) + subprocess.call(["/usr/bin/twmnc", "-t", escape(title), "-c", escape(body)]) + else: + #subprocess.call(["/usr/bin/twmnc", "-u", urgency, "-c", "IRC", "-i", icon, escape(title), escape(body)]) + subprocess.call(["/usr/bin/twmnc", "-t", "IRC", "-c", escape(title), escape(body)]) + + except ValueError as e: + print e + except OSError as e: + print e + accept_connections(s, timeout) + +def weechat_client(argv): + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + s.bind(("localhost", int(argv[1] if len(sys.argv) > 1 else 4321))) + s.listen(5) + try: + accept_connections(s, argv[2] if len(sys.argv) > 2 else None) + except KeyboardInterrupt as e: + print "Keyboard interrupt" + print e + finally: + s.close() + +if __name__ == '__main__': + if in_weechat: + weechat_script() + else: + weechat_client(sys.argv) diff --git a/dotfiles/scripts/searx.sh b/dotfiles/scripts/searx.sh new file mode 100755 index 0000000..876d6d1 --- /dev/null +++ b/dotfiles/scripts/searx.sh @@ -0,0 +1,3 @@ +#!/bin/bash +sudo systemctl start httpd.service +python /srv/searx/searx/webapp.py diff --git a/dotfiles/scripts/ssh.sh b/dotfiles/scripts/ssh.sh new file mode 100755 index 0000000..7116490 --- /dev/null +++ b/dotfiles/scripts/ssh.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +#By default the sshd listen only for local connection. + +if [[ $1 == "disable" ]]; then + if [[ $(cat /etc/ssh/sshd_config | grep -e "^ListenAddress") == "" ]]; then + sudo sed -i -e 's/#ListenAddress ::/#ListenAddress ::\nListenAddress 127.0.0.1/g' /etc/ssh/sshd_config + sudo systemctl restart sshd.service + fi + echo "sshd listen now only for local address 127.0.0.1." +elif [[ $1 == "enable" ]]; then + sudo sed -i -e '/ListenAddress 127.0.0.1/d' /etc/ssh/sshd_config + sudo systemctl restart sshd.service + echo "sshd listen now for all address." +elif [[ $1 == "status" ]]; then + echo $(sudo systemctl status sshd.service) + echo "sshd conf say:" + echo $(cat /etc/ssh/sshd_config | grep -e "^ListenAddress") +elif [[ $1 == "start" || $1 == "stop" || $1 == "restart" ]]; then + sudo systemctl $1 sshd.service +fi + +sudo -k + diff --git a/dotfiles/scripts/switch-workspace.py b/dotfiles/scripts/switch-workspace.py new file mode 100755 index 0000000..d311c46 --- /dev/null +++ b/dotfiles/scripts/switch-workspace.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +from json import loads +from os import popen +from sys import argv + +def ipc_query(req="command", msg=""): + ans = popen("i3-msg -t " + req + " " + msg).readlines()[0] + return loads(ans) + +if __name__ == "__main__": + # Usage & checking args + if len(argv) != 2: + print ("Usage: switch-workspace.py name-of-workspace") + exit(-1) + + newworkspace = argv[1] + + # Retrieving active display + active_display = None + old_display = None + for w in ipc_query(req="get_workspaces"): + if w['focused']: + active_display = w['output'] + if w['name'] == newworkspace: + old_display = w['output'] + if newworkspace.isdigit() and w['num'] == int(newworkspace): + old_display = w['output'] + print (w) + + # Pre-computing commands + if newworkspace.isdigit(): + cmd_show = "workspace number " + newworkspace + else: + cmd_show = "workspace " + newworkspace + cmd_move = "move workspace to output " + active_display + + # Moving workspace to active display + if active_display == old_display: + print (cmd_show) + print (ipc_query(msg=cmd_show)) + else: + cmd="'" + cmd_show + ";" + cmd_move + ";" + cmd_show + "'" + print (cmd) + print (ipc_query(msg=cmd)) diff --git a/dotfiles/scripts/switch_audio.sh b/dotfiles/scripts/switch_audio.sh new file mode 100755 index 0000000..aff2543 --- /dev/null +++ b/dotfiles/scripts/switch_audio.sh @@ -0,0 +1,16 @@ +#/bin/sh + +# Usage : +# switch_audio.sh + +headphones="analog-output-headphones" +lineout="analog-output-lineout" +sinkport="$1" + +if [[ $(echo $(pacmd list | grep "active port") | cut -d" " -f3 | cut -d"<" -f2 | cut -d">" -f1) == $lineout ]] +then + pacmd set-sink-port $sinkport $headphones + elif [[ $(echo $(pacmd list | grep "active port") | cut -d" " -f3 | cut -d"<" -f2 | cut -d">" -f1) == $headphones ]] + then + pacmd set-sink-port $sinkport $lineout + fi diff --git a/dotfiles/scripts/task b/dotfiles/scripts/task new file mode 100755 index 0000000..f15e4a6 --- /dev/null +++ b/dotfiles/scripts/task @@ -0,0 +1,28 @@ +#!/bin/sh +SESSION=task + +optios $@ + +tmux kill-session -t $SESSION +tmux -2 new-session -d -s $SESSION +tmux send-keys "watch task calendar" C-m +tmux split-window -v +tmux resize-pan -D 10 +tmux resize-pan -U 10 +tmux send-keys "watch task $@" C-m +tmux split-window -v +tmux resize-pan -D 20 +tmux resize-pan -U 5 +l1="┳━┓┓ ┃┳━┓┏┏┓┳━┓┳ ┳━┓ ┏━┓┳━┓ ┓━┓┏━┓┏┏┓┳━┓ ┏━┓┏━┓┏┏┓┏┏┓┳━┓┏┓┓┳━┓┓━┓" +l2="┣━ ┏╋┛┃━┫┃┃┃ ┃━┛┃ ┣━ ┃ ┃┣━ ┗━┓┃ ┃┃┃┃ ┣━ ┃ ┃ ┃┃┃┃ ┃┃┃ ┃━┫┃┃┃┃ ┃┗━┓" +l3="┻━┛┇ ┗┛ ┇┛ ┇┇ ┇━┛┻━┛ ┛━┛┇ ━━┛┛━┛┛ ┇┻━┛ ┗━┛┛━┛┛ ┇┛ ┇┛ ┇┇┗┛┇━┛━━┛" +tmux send-keys "clear;echo -e '$l1\n$l2\n$l3\n\ntmux send-keys -t task:0.1 C-c \`\` C-m\nMore info about task on the next page !'" C-m +tmux split-window -v +tmux resize-pan -D 5 +tmux new-window +tmux select-window -t 1 +tmux send-keys "task help | less" C-m +tmux select-window -t 0 +tmux rename-window -t 0 "task" +tmux rename-window -t 1 "help" +tmux -2 attach-session -t $SESSION diff --git a/dotfiles/scripts/tdone b/dotfiles/scripts/tdone new file mode 100755 index 0000000..d63fd87 --- /dev/null +++ b/dotfiles/scripts/tdone @@ -0,0 +1,30 @@ +#!/bin/bash + +usage () { + echo "Usage:" + echo " tdone