From c2cafe592eacfe43bf518467fbdb149b829e6cad Mon Sep 17 00:00:00 2001 From: Urbain Vaes Date: Fri, 27 Oct 2017 01:07:11 +0200 Subject: Clean up --- bin/bin/auto-open-download | 13 --------- bin/bin/downloads | 7 ++--- bin/bin/email | 16 ----------- bin/bin/monitor | 2 +- bin/bin/move_workspace | 21 -------------- bin/bin/references | 2 +- bin/bin/run | 6 ++-- bin/bin/touchpad | 9 ------ bin/bin/username | 7 ++--- bin/bin/vimin | 4 --- bin/bin/workspace | 69 ++++++++++++++++++++++++++++++---------------- 11 files changed, 54 insertions(+), 102 deletions(-) delete mode 100755 bin/bin/auto-open-download delete mode 100755 bin/bin/email delete mode 100755 bin/bin/move_workspace delete mode 100755 bin/bin/touchpad delete mode 100755 bin/bin/vimin (limited to 'bin') diff --git a/bin/bin/auto-open-download b/bin/bin/auto-open-download deleted file mode 100755 index 1ebeac2..0000000 --- a/bin/bin/auto-open-download +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -inotifywait -m -q -e create $HOME/Downloads | while read line -do - extension=${line##*.} - file=$HOME/Downloads/$(echo "$line" | cut -d " " -f 3-) - if [[ $extension =~ (pdf|PDF|ps|djvu) ]] ; then - while test $(find "$file" -mmin "-0.02"); do - sleep 0.02 - done - zathura "$file" - fi -done diff --git a/bin/bin/downloads b/bin/bin/downloads index b3583b9..46d64bd 100755 --- a/bin/bin/downloads +++ b/bin/bin/downloads @@ -1,5 +1,4 @@ #!/bin/bash -DOWNLOAD_DIR="$HOME/Downloads" -PDF=$(ls -t $DOWNLOAD_DIR/*.pdf $DOWNLOAD_DIR/*.PDF $DOWNLOAD_DIR/*.djvu $DOWNLOAD_DIR/*.ps) -TARGET=$(echo "${PDF//"$DOWNLOAD_DIR/"/}" | dmenu -i -p "Open File:") -[[ -n $TARGET ]] && zathura "$DOWNLOAD_DIR/$TARGET" & +download_dir="$HOME/Downloads" +target=$(find $download_dir -regex '.*\.\(pdf\|PDF\|djvu\|ps\)' -printf "%f\n" | dmenu -i -p "Open File:") +[[ -n $target ]] && exec zathura "$download_dir/$target" diff --git a/bin/bin/email b/bin/bin/email deleted file mode 100755 index c2f9998..0000000 --- a/bin/bin/email +++ /dev/null @@ -1,16 +0,0 @@ -#! /usr/bin/env bash - -# Necessary to see the notification -export DISPLAY=:0 - -# Get all emails -mbsync -a - -new_mails=$(find $HOME/.mail -path '*/new/*' -type f -not -path '*/rss/*') - -if [[ ! -z ${new_mails} ]]; then - subjects=$(cat $(echo -e ${new_mails/'\n'/' '}) | grep "^Subject: " | sed "s/^Subject: //g") - DISPLAY=:0 /usr/bin/notify-send -t 3 "New mail(s)!" "${subjects}" -fi - -echo "Email last checked on $(date)". diff --git a/bin/bin/monitor b/bin/bin/monitor index 6f4267e..c3b81db 100755 --- a/bin/bin/monitor +++ b/bin/bin/monitor @@ -54,7 +54,7 @@ do then TILES[$index]="Dual Screen ${MONITORS[$entry_a]} -> ${MONITORS[$entry_b]}" COMMANDS[$index]="xrandr --output ${MONITORS[$entry_a]} --auto \ - --left-of ${MONITORS[$entry_b]} --auto" + --output ${MONITORS[$entry_b]} --auto --right-of ${MONITORS[$entry_a]}" index+=1 fi diff --git a/bin/bin/move_workspace b/bin/bin/move_workspace deleted file mode 100755 index a56ff3f..0000000 --- a/bin/bin/move_workspace +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash - -wkspces=$(i3-msg -t get_workspaces | grep -Po '"name":.*?[^\\]"' | sed 's/"name":"\([^"]\+\)"/\1/g') -focused=$(i3-msg -t get_workspaces | grep -Po '{[^}]*"focused":true[^}]*}' | sed 's/.*"name":"\([^"]*\)".*$/\1/g') - -focused_number=${focused%%:*} -focused_name=${focused#*:} - -[[ $1 = 'n' ]] && new_number=$((focused_number + 1)) -[[ $1 = 'p' ]] && new_number=$((focused_number - 1)) - -next=$(echo "${wkspces}" | grep "^${new_number}") - -i3-msg rename workspace to ${new_number}:${focused_name} - -if [[ ! -z "${next// }" ]]; then - name_next=${next#*:} - i3-msg "workspace ${next};\ - rename workspace to ${focused_number}:${name_next};\ - workspace ${new_number}:${focused_name}" -fi diff --git a/bin/bin/references b/bin/bin/references index 4e6346a..a4662d2 100755 --- a/bin/bin/references +++ b/bin/bin/references @@ -2,4 +2,4 @@ REF_DIR="$HOME/phd/references" PDF=$(find $REF_DIR -name "*.pdf" -printf "%P\n") TARGET=$(echo "${PDF//"$REF_DIR/"/}" | dmenu -i -p "Open File:") -[[ -n $TARGET ]] && (zathura "$REF_DIR/$TARGET" &) +[[ -n $TARGET ]] && exec zathura "$REF_DIR/$TARGET" diff --git a/bin/bin/run b/bin/bin/run index b5ff85d..aef09ea 100755 --- a/bin/bin/run +++ b/bin/bin/run @@ -1,5 +1,3 @@ #!/bin/bash -SCRIPTS_DIR="$HOME/bin" && cd $SCRIPTS_DIR -SCRIPTS=$(ls -A $SCRIPTS_DIR) -TARGET=$(echo "${SCRIPTS//"$SCRIPTS_DIR/"/}" | dmenu -i -p "Run script:") -[[ -n $TARGET ]] && "$TARGET" +target=$(find $HOME/dotfiles/bin/ -type f -not -name ".*" -printf "%f\n" | dmenu -i -p "Run script:") +[[ -n $target ]] && exec $target diff --git a/bin/bin/touchpad b/bin/bin/touchpad deleted file mode 100755 index 17649fa..0000000 --- a/bin/bin/touchpad +++ /dev/null @@ -1,9 +0,0 @@ -#! /usr/bin/env bash - -# Touchpad status -status=$(synclient -l | grep TouchpadOff) -if [[ $status = *1 ]]; then - synclient TouchpadOff=0 -elif [[ $status = *0 ]]; then - synclient TouchpadOff=1 -fi diff --git a/bin/bin/username b/bin/bin/username index 37da88a..704ea98 100755 --- a/bin/bin/username +++ b/bin/bin/username @@ -1,6 +1,3 @@ #!/bin/bash -PWD_DIR="$HOME/.password-store" -[[ ! -z $(readlink ${PWD_DIR}) ]] && PWD_DIR=$(readlink ${PWD_DIR}) -PASSWORDS=$(locate "${PWD_DIR}/**/*.gpg") -TARGET=$(echo "${PASSWORDS//"$PWD_DIR/"/}" | dmenu -i -p "Get identifier for:") -basename $TARGET .gpg | xclip -i +target=$(find $HOME/.password-store/ -name "*.gpg" -exec sh -c 'echo ${1#*password-store/}' _ {} \; | dmenu -i -p "Get identifier for:") +basename $target .gpg | xclip -i diff --git a/bin/bin/vimin b/bin/bin/vimin deleted file mode 100755 index b00d8fa..0000000 --- a/bin/bin/vimin +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -tempfile=$(mktemp) -urxvt -e nvim ${tempfile} +star -cat ${tempfile} | xclip -i diff --git a/bin/bin/workspace b/bin/bin/workspace index 79ff834..51c488a 100755 --- a/bin/bin/workspace +++ b/bin/bin/workspace @@ -1,33 +1,54 @@ -#!/bin/zsh - -# Command to use -[[ $1 = 'n' ]] && cmd="workspace" -[[ $1 = 'm' ]] && cmd="move container to workspace" +#!/usr/bin/env bash # List of workspaces -workspaces=$(i3-msg -t get_workspaces | grep -Po '"name":.*?[^\\]"' | sed 's/"name":"\([^"]\+\)"/\1/g') +workspaces=$(i3-msg -t get_workspaces | awk 'BEGIN { + RS="(},{)|(\\[{)|(}\\])"; + FPAT="([^,:]+)|([^,]+{[^}]+})|(\"[^\"]+\")" + } + $0 !~ "^\\s*$" { + gsub(/"/, "", $4) + print $2, $4, $8, $11 + }' | sort) + +act_on_container() { + # Get desired workspace + target=$(echo "$workspaces" | awk '{print $2}' | dmenu -i -p "Select workspace: ") + + # Exit if empty + [[ -z $target ]] && exit -# Keep only the ones containing : -workspaces=$(echo $workspaces | sed '/:/!d') + # If new workspace has to be created + if [[ ! $target = [0-9]* ]]; then -# Get desired workspace -target=$(echo $workspaces | dmenu "Go to workspace:") + # Add number to workspace name + new_number=$(echo "$workspaces" | awk '$1!=p+1{exit;}{p=$1} END {print p+1}') + target=$new_number:$target + fi -# Exit if empty -[[ -z $target ]] && exit + # Execute command + exec i3-msg $1 $target +} -# If new workspace has to be created -if [[ ! $target = [0-9]* ]]; then +act_on_workspace() { + focused_number=$(echo "$workspaces" | awk '$3 ~ "true" {print $1}') + focused_name=$(echo "$workspaces" | awk '$3 ~ "true" {print $2}' | cut -d":" -f2) - # Calculate number for new workspace - used_numbers=$(echo $workspaces | awk 'BEGIN { FS = ":" } ; { print $1 }' | sort) - max_number=$(echo $used_numbers | tail -1) - lowest_gap=$(echo $used_numbers | awk '$1!=p+1{print p+1}{p=$1}' | head -1) - [[ -z $lowest_gap ]] && new_number=$(($max_number + 1)) || new_number=$lowest_gap + [[ $1 = 'n' ]] && new_number=$((focused_number + 1)) + [[ $1 = 'p' ]] && new_number=$((focused_number - 1)) - # Add number to workspace name - target=$new_number:$target -fi + next=$(echo "${workspaces}" | awk '$1 ~ /'$new_number'/ {print $2}') -# Execute command -exec i3-msg $cmd $target + i3-msg rename workspace to ${new_number}:${focused_name} + + if [[ ! -z "${next// }" ]]; then + name_next=${next#*:} + i3-msg "workspace ${next};\ + rename workspace to ${focused_number}:${name_next};\ + workspace ${new_number}:${focused_name}" + fi +} + +# Command to use +[[ $1 = 'gw' ]] && act_on_container "workspace" +[[ $1 = 'mc' ]] && act_on_container "move container to workspace" +[[ $1 = 'mw' ]] && act_on_workspace "$2" -- cgit v1.2.3