From e146e947c52ac4adbe426b3f893faff1e46ed5f8 Mon Sep 17 00:00:00 2001 From: Urbain Vaes Date: Tue, 19 Apr 2016 15:24:25 +0100 Subject: Use GNU stow for dotfiles management --- bin/bin/books | 5 + bin/bin/dot | 48 +++++++++ bin/bin/downloads | 5 + bin/bin/email | 16 +++ bin/bin/i3-shell | 27 ++++++ bin/bin/id | 6 ++ bin/bin/keyboard | 36 +++++++ bin/bin/mystatus | 9 ++ bin/bin/password | 2 + bin/bin/recolor | 8 ++ bin/bin/rename_workspace | 12 +++ bin/bin/run | 5 + bin/bin/swap | 16 +++ bin/bin/tldr | 246 +++++++++++++++++++++++++++++++++++++++++++++++ bin/bin/tmux_attach | 9 ++ bin/bin/touchpad | 9 ++ bin/bin/vimin | 4 + bin/bin/workspace | 33 +++++++ bin/books | 5 - bin/dot | 48 --------- bin/downloads | 5 - bin/email | 16 --- bin/i3-shell | 27 ------ bin/id | 6 -- bin/keyboard | 36 ------- bin/mystatus | 9 -- bin/password | 2 - bin/recolor | 8 -- bin/rename_workspace | 12 --- bin/run | 5 - bin/swap | 16 --- bin/tldr | 246 ----------------------------------------------- bin/tmux_attach | 9 -- bin/touchpad | 9 -- bin/vimin | 4 - bin/workspace | 33 ------- 36 files changed, 496 insertions(+), 496 deletions(-) create mode 100755 bin/bin/books create mode 100755 bin/bin/dot create mode 100755 bin/bin/downloads create mode 100755 bin/bin/email create mode 100755 bin/bin/i3-shell create mode 100755 bin/bin/id create mode 100755 bin/bin/keyboard create mode 100755 bin/bin/mystatus create mode 100755 bin/bin/password create mode 100755 bin/bin/recolor create mode 100755 bin/bin/rename_workspace create mode 100755 bin/bin/run create mode 100755 bin/bin/swap create mode 100755 bin/bin/tldr create mode 100755 bin/bin/tmux_attach create mode 100755 bin/bin/touchpad create mode 100755 bin/bin/vimin create mode 100755 bin/bin/workspace delete mode 100755 bin/books delete mode 100755 bin/dot delete mode 100755 bin/downloads delete mode 100755 bin/email delete mode 100755 bin/i3-shell delete mode 100755 bin/id delete mode 100755 bin/keyboard delete mode 100755 bin/mystatus delete mode 100755 bin/password delete mode 100755 bin/recolor delete mode 100755 bin/rename_workspace delete mode 100755 bin/run delete mode 100755 bin/swap delete mode 100755 bin/tldr delete mode 100755 bin/tmux_attach delete mode 100755 bin/touchpad delete mode 100755 bin/vimin delete mode 100755 bin/workspace (limited to 'bin') diff --git a/bin/bin/books b/bin/bin/books new file mode 100755 index 0000000..8524277 --- /dev/null +++ b/bin/bin/books @@ -0,0 +1,5 @@ +#!/bin/bash +BOOKS_DIR="$HOME/Dropbox/books" +PDF=$(locate "$BOOKS_DIR/*.pdf") +TARGET=$(echo "${PDF//"$BOOKS_DIR/"/}" | dmenu -i -p "Open File:") +[[ -n $TARGET ]] && zathura "$BOOKS_DIR/$TARGET" & diff --git a/bin/bin/dot b/bin/bin/dot new file mode 100755 index 0000000..acb0e64 --- /dev/null +++ b/bin/bin/dot @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +get_links() +{ + find $HOME -not -path "$HOME/dotfiles/*" -type l | while read line; do + if [[ "$(realpath -q $line)" == "${HOME}/dotfiles/"* ]]; then + echo $line + fi + done +} + +clean() +{ + get_links | while read link; do + rm -v ${link} + done +} + +down() +{ + source $HOME/dotfiles/.dotmap + for link in "${!dotmap[@]}"; do + echo "Removing ${link}." + rm -rf $link + done +} + +up() +{ + source $HOME/dotfiles/.dotmap + for link in "${!dotmap[@]}"; do + target=${dotmap[$link]} + mkdir -p $(dirname ${link}) + echo "Linking $target." + rm -rf $link && ln -s $target $link + done +} + +save() +{ + echo "declare -A dotmap" > .dotmap + get_links | while read link; do + echo "dotmap[$link]=$(readlink -f -q $link)" | sed "s#$HOME#"'$HOME#g' >> .dotmap + done + sort .dotmap -o .dotmap +} + +$1 diff --git a/bin/bin/downloads b/bin/bin/downloads new file mode 100755 index 0000000..c4c306e --- /dev/null +++ b/bin/bin/downloads @@ -0,0 +1,5 @@ +#!/bin/bash +DOWNLOAD_DIR="$HOME/Downloads" +PDF=$(ls -t $DOWNLOAD_DIR/*.pdf) +TARGET=$(echo "${PDF//"$DOWNLOAD_DIR/"/}" | dmenu -i -p "Open File:") +[[ -n $TARGET ]] && zathura "$DOWNLOAD_DIR/$TARGET" & diff --git a/bin/bin/email b/bin/bin/email new file mode 100755 index 0000000..84e923e --- /dev/null +++ b/bin/bin/email @@ -0,0 +1,16 @@ +#! /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) +subjects=$(cat $(echo -e ${new_mails/'\n'/' '}) | grep "^Subject: " | sed "s/^Subject: //g") + +if [[ ! -z ${new_mails} ]]; then + /usr/bin/notify-send -t 3 "New mail(s)!" "${subjects}" +fi + +echo "Email last checked on $(date)". diff --git a/bin/bin/i3-shell b/bin/bin/i3-shell new file mode 100755 index 0000000..120e4b4 --- /dev/null +++ b/bin/bin/i3-shell @@ -0,0 +1,27 @@ +#!/bin/bash +# i3 thread: https://faq.i3wm.org/question/150/how-to-launch-a-terminal-from-here/?answer=152#post-id-152 + +CMD=urxvt +CWD='' + +# Get window ID +ID=$(xdpyinfo | grep focus | cut -f4 -d " ") + +# Get PID of process whose window this is +PID=$(xprop -id $ID | grep -m 1 PID | cut -d " " -f 3) + +# Get last child process (shell, vim, etc) +if [ -n "$PID" ]; then + TREE=$(pstree -lpA $PID | tail -n 1) + PID=$(echo $TREE | awk -F'---' '{print $NF}' | sed -re 's/[^0-9]//g') + + # If we find the working directory, run the command in that directory + if [ -e "/proc/$PID/cwd" ]; then + CWD=$(readlink /proc/$PID/cwd) + fi +fi +if [ -n "$CWD" ]; then + cd $CWD && $CMD +else + $CMD +fi diff --git a/bin/bin/id b/bin/bin/id new file mode 100755 index 0000000..7dad85d --- /dev/null +++ b/bin/bin/id @@ -0,0 +1,6 @@ +#! /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 diff --git a/bin/bin/keyboard b/bin/bin/keyboard new file mode 100755 index 0000000..5a96bcb --- /dev/null +++ b/bin/bin/keyboard @@ -0,0 +1,36 @@ +# Dvorak programer +setxkbmap us -variant dvp + +# Make caps lock a Control +xmodmap -e "clear Lock" +xmodmap -e "keysym Caps_Lock = Control_L Control_L" +xmodmap -e "add Control = Control_L" + +# Remap modifiers (Keyboard dependent) +xmodmap -e "keycode 94 = Mode_switch" +# xmodmap -e 'keycode 108 = Super_L' + +# Remap modifiers (Keyboard independent) +xmodmap -e 'keysym space = Super_L' +xmodmap -e 'keycode any = space' + +# Numbers +xmodmap -e "keysym d = d D 0" +xmodmap -e "keysym o = o O 1" +xmodmap -e "keysym m = m M 1" +xmodmap -e "keysym e = e E 2" +xmodmap -e "keysym w = w W 2" +xmodmap -e "keysym u = u U 3" +xmodmap -e "keysym v = v V 3" +xmodmap -e "keysym h = h H 4" +xmodmap -e "keysym t = t T 5" +xmodmap -e "keysym n = n N 6" +xmodmap -e "keysym g = g G 7" +xmodmap -e "keysym c = c C 8" +xmodmap -e "keysym r = r R 9" + +# Xcape settings +killall -9 xcape + +xcape -e 'Control_L=Escape' +xcape -e 'Super_L=space' diff --git a/bin/bin/mystatus b/bin/bin/mystatus new file mode 100755 index 0000000..b26e9b6 --- /dev/null +++ b/bin/bin/mystatus @@ -0,0 +1,9 @@ +#!/bin/sh +# shell script to prepend i3status with more stuff + +i3status | while : +do + read line + nmails=$(find $HOME/.mail -path '*/new/*' -type f | wc -l) + echo "Email: ${nmails} | $line" || exit 1 +done diff --git a/bin/bin/password b/bin/bin/password new file mode 100755 index 0000000..065672b --- /dev/null +++ b/bin/bin/password @@ -0,0 +1,2 @@ +#! /bin/bash +passmenu diff --git a/bin/bin/recolor b/bin/bin/recolor new file mode 100755 index 0000000..edd5fa5 --- /dev/null +++ b/bin/bin/recolor @@ -0,0 +1,8 @@ +#!/bin/sh + +tr -d ' \t' | sed -n ' +s/.*background:/\x1b]11;/p +s/.*foreground:/\x1b]10;/p +s/.*borderColor:/\x1b]708;/p +s/.*color\([0-9][^:]*\):/\x1b]4;\1;/p +' | tr \\n \\a diff --git a/bin/bin/rename_workspace b/bin/bin/rename_workspace new file mode 100755 index 0000000..7636fd2 --- /dev/null +++ b/bin/bin/rename_workspace @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +workspace=$(i3-msg -t get_outputs | grep -Po '"current_workspace":"[^\"]*"' | sed 's/"current_workspace":"\([^"]\+\)"/\1/g') +number=$(echo "${workspace//[!0-9]}") + +new_name=$(zenity --entry --title="Rename workspace" --entry-text "$workspace") +if [[ "$new_name" != *:* ]]; then + new_name="$number:$new_name" +fi + +echo $new_name +exec i3-msg rename workspace to "$new_name" diff --git a/bin/bin/run b/bin/bin/run new file mode 100755 index 0000000..8ca03eb --- /dev/null +++ b/bin/bin/run @@ -0,0 +1,5 @@ +#!/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 ]] && "$SCRIPTS_DIR/$TARGET" diff --git a/bin/bin/swap b/bin/bin/swap new file mode 100755 index 0000000..4c17dc7 --- /dev/null +++ b/bin/bin/swap @@ -0,0 +1,16 @@ +#!/usr/bin/python + +import i3 +outputs = i3.get_outputs() +print(outputs[0]) + +# set current workspace to output 0 +i3.workspace(outputs[0]['current_workspace']) + +# ..and move it to the other output. +# outputs wrap, so the right of the right is left ;) +i3.command('move', 'workspace to output right') + +# rinse and repeat +i3.workspace(outputs[1]['current_workspace']) +i3.command('move', 'workspace to output right') diff --git a/bin/bin/tldr b/bin/bin/tldr new file mode 100755 index 0000000..2b294c0 --- /dev/null +++ b/bin/bin/tldr @@ -0,0 +1,246 @@ +#!/bin/bash +# tldr client by Ray Lee, http://github.com/raylee/tldr +# a Sunday afternoon's project, I'm sure there's room for improvement. PRs welcome! + +set -uf -o pipefail + +# initialize globals, sanity check the environment, etc. +config() { + init_term_cmds + + if [ -z $(which curl) ]; then + echo "${red}tldr requires \`curl\` installed in your path$reset" + exit 1 + fi + + configdir=~/.tldr + [ -d ~/.config ] && configdir=~/.config/tldr + + platform=$(get_platform) + base_url="https://raw.githubusercontent.com/tldr-pages/tldr/master/pages" + index_url="http://tldr-pages.github.io/assets/index.json" + index="$configdir/index.json" + cache_days=14 + force_update='' + + #check if config folder exists, otherwise create it + [ -d "$configdir" ] || mkdir -p "$configdir" + + [ ! -f $index ] && update_index + auto_update_index +} + +update_index() { + curl -sf -o "$index" "$index_url" + res=$? + if [ $res -eq 22 ]; then + echo "Could not download index from $index_url" + exit 1 + fi +} + +# if the file exists and is more recent than $cache_days old +recent() { + exists=$(find "$1" -mtime -$cache_days 2>/dev/null) + [ -n "$exists" -a -z "$force_update" ] +} + +auto_update_index() { + recent "$index" || update_index +} + +# function contents via http://mywiki.wooledge.org/BashFAQ/037 +init_term_cmds() { + # only set if we're on an interactive session + [[ -t 2 ]] && { + reset=$( tput sgr0 || tput me ) # Reset cursor + bold=$( tput bold || tput md ) # Start bold + under=$( tput smul || tput us ) # Start underline + italic=$( tput sitm || tput ZH ) # Start italic + eitalic=$( tput ritm || tput ZH ) # End italic + default=$( tput op ) + back=$'\b' + + [[ $TERM != *-m ]] && { + black=$( tput setaf 0 || tput AF 0 ) + red=$( tput setaf 1 || tput AF 1 ) + green=$( tput setaf 2 || tput AF 2 ) + yellow=$( tput setaf 3 || tput AF 3 ) + blue=$( tput setaf 4 || tput AF 4 ) + magenta=$( tput setaf 5 || tput AF 5 ) + cyan=$( tput setaf 6 || tput AF 6 ) + white=$( tput setaf 7 || tput AF 7 ) + + onblue=$( tput setab 4 || tput AB 4 ) + ongrey=$( tput setab 7 || tput AB 7 ) + } + } 2>/dev/null ||: + + # osx's termcap doesn't have italics. The below adds support for iTerm2 + # and is harmless on Terminal.app + [ "$(get_platform)" = "osx" ] && { + italic=$(echo -e "\033[3m") + eitalic=$(echo -e "\033[23m") + } +} + +heading() { + local line="$*" + echo "$bold$red${line:2}$reset" +} + +quotation() { + local line="$*" + echo "$under${line:2}$reset" +} + +list_item() { + local line="$*" + echo "$line$reset" +} + +code() { + local line="$*" + # I'm sure there's a better way to strip the first and last characters. + line="${line:1}" + line="${line%\`}" + # convert {{variable}} to italics + line=${line//\{\{/$italic} + line=${line//\}\}/$eitalic} + + echo "$bold$line$reset" +} + +text() { + local line="$*" + echo "$line" +} + +# an idiot-level recognition of tldr's markdown. Needs improvement, or +# subcontracting out to a markdown -> ANSI formatting command +display_tldr() { + # read one line at a time, don't strip whitespace ('IFS='), and process + # last line even if it doesn't have a newline at the end + while IFS= read -r line || [[ -n "$line" ]]; do + start=${line:0:1} # get the first character + case "$start" in + '#') heading "$line" + ;; + '>') quotation "$line" + ;; + '-') list_item "$line" + ;; + '`') code "$line" + ;; + *) text "$line" + ;; + esac + done +} + +# convert the local platorm name to tldr's version +get_platform() { + case `uname -s` in + Darwin) echo "osx" ;; + Linux) echo "linux" ;; + SunOS) echo "sunos" ;; + *) echo "common" ;; + esac +} + +# extract the platform key from index.json, return preferred subpath to tldrpage +path_for_cmd() { + local desc=$(tr '{' '\n' < $index | grep "\"name\":\"$1\"") + # results in, eg, "name":"netstat","platform":["linux","osx"]}, + + [ -z "$desc" ] && return + + # use the platform specific version of the tldr first + if [[ $desc =~ \"$platform\" ]]; then + echo "$platform/$1.md" + elif [[ $desc =~ \"common\" ]]; then + echo "common/$1.md" + else + # take the first one so we can show something, but warn the user + local p=$(echo "$desc" | cut -d '"' -f 8) + >&2 echo -e "${red}tldr page $1 not found in $platform or common, using page from platform $p instead$reset\n" + echo "$p/$1.md" + fi +} + +# return the local cached copy of the tldrpage, or retrieve and cache from github +get_tldr() { + local p="$(path_for_cmd $1)" + cached="$configdir/$p" + recent "$cached" || { + mkdir -p $(dirname $cached) + curl -sf -o "$cached" "$base_url/$p" + } + # if the curl failed for some reason, keep cat from whinging + cat "$cached" 2>/dev/null +} + + +config + +usage() { + cmd=$(basename $0) + cat < + +[options] + -l, --list: show all available pages + -p, --platform: show page from specific platform rather than autodetecting + -u, --update: update, force retrieving latest copies of locally cached files + -h, -?, --help: this help overview + + + Show examples for this command + +The client caches a copy of all pages and the index locally under +$configdir. By default, the cached copies will expire in $cache_days days. + +EOF +exit 0 +} + +while [ $# -gt 0 ] +do + case "$1" in + -l|--list) + >&2 echo -e "Known tldr pages: \n" + tr '{' '\n' < "$configdir/index.json" | cut -d '"' -f4 | column + exit 0 + ;; + -u|--update) + force_update=yes + update_index + ;; + -h|-\?|--help) + usage + ;; + -p|--platform) + shift + platform=$1 + ;; + -*) + usage + ;; + *) + page=${1:-''} + ;; + esac + shift +done + +[ -z ${page:-} ] && usage + +tldr="$(get_tldr $page)" + +if [ -z "$tldr" ]; then + echo "tldr page for command $page not found" + exit 1 +fi + +display_tldr <<< "$tldr" +echo diff --git a/bin/bin/tmux_attach b/bin/bin/tmux_attach new file mode 100755 index 0000000..564e3bb --- /dev/null +++ b/bin/bin/tmux_attach @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +SESSIONS=$(tmux list-sessions | cut -d':' -f1) + +SESSION=$(echo "$SESSIONS" | dmenu -i -p "Session:" | tr -d '[[:space:]]') + +[[ -n $SESSION ]] || exit + +urxvt -e zsh -c "tmux new-session -A -s $SESSION" diff --git a/bin/bin/touchpad b/bin/bin/touchpad new file mode 100755 index 0000000..17649fa --- /dev/null +++ b/bin/bin/touchpad @@ -0,0 +1,9 @@ +#! /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/vimin b/bin/bin/vimin new file mode 100755 index 0000000..905b30f --- /dev/null +++ b/bin/bin/vimin @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +tempfile=$(mktemp) +urxvt -e vim ${tempfile} +cat ${tempfile} | xclip -i diff --git a/bin/bin/workspace b/bin/bin/workspace new file mode 100755 index 0000000..a9e4aa0 --- /dev/null +++ b/bin/bin/workspace @@ -0,0 +1,33 @@ +#!/bin/zsh + +# Command to use +[[ $1 = 'n' ]] && cmd="workspace" +[[ $1 = 'm' ]] && cmd="move container to workspace" + +# List of workspaces +workspaces=$(i3-msg -t get_workspaces | grep -Po '"name":.*?[^\\]"' | sed 's/"name":"\([^"]\+\)"/\1/g') + +# Keep only the ones containing : +workspaces=$(echo $workspaces | sed '/:/!d') + +# Get desired workspace +target=$(echo $workspaces | dmenu -b -i -sf green -p "Go to workspace:") + +# Exit if empty +[[ -z $target ]] && exit + +# If new workspace has to be created +if [[ ! $target = [0-9]* ]]; then + + # Calculate number for new workspace + used_numbers=$(echo $workspaces | awk 'BEGIN { FS = ":" } ; { print $1 }') + 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 + + # Add number to workspace name + target=$new_number:$target +fi + +# Execute command +exec i3-msg $cmd $target diff --git a/bin/books b/bin/books deleted file mode 100755 index 8524277..0000000 --- a/bin/books +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -BOOKS_DIR="$HOME/Dropbox/books" -PDF=$(locate "$BOOKS_DIR/*.pdf") -TARGET=$(echo "${PDF//"$BOOKS_DIR/"/}" | dmenu -i -p "Open File:") -[[ -n $TARGET ]] && zathura "$BOOKS_DIR/$TARGET" & diff --git a/bin/dot b/bin/dot deleted file mode 100755 index acb0e64..0000000 --- a/bin/dot +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash - -get_links() -{ - find $HOME -not -path "$HOME/dotfiles/*" -type l | while read line; do - if [[ "$(realpath -q $line)" == "${HOME}/dotfiles/"* ]]; then - echo $line - fi - done -} - -clean() -{ - get_links | while read link; do - rm -v ${link} - done -} - -down() -{ - source $HOME/dotfiles/.dotmap - for link in "${!dotmap[@]}"; do - echo "Removing ${link}." - rm -rf $link - done -} - -up() -{ - source $HOME/dotfiles/.dotmap - for link in "${!dotmap[@]}"; do - target=${dotmap[$link]} - mkdir -p $(dirname ${link}) - echo "Linking $target." - rm -rf $link && ln -s $target $link - done -} - -save() -{ - echo "declare -A dotmap" > .dotmap - get_links | while read link; do - echo "dotmap[$link]=$(readlink -f -q $link)" | sed "s#$HOME#"'$HOME#g' >> .dotmap - done - sort .dotmap -o .dotmap -} - -$1 diff --git a/bin/downloads b/bin/downloads deleted file mode 100755 index c4c306e..0000000 --- a/bin/downloads +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -DOWNLOAD_DIR="$HOME/Downloads" -PDF=$(ls -t $DOWNLOAD_DIR/*.pdf) -TARGET=$(echo "${PDF//"$DOWNLOAD_DIR/"/}" | dmenu -i -p "Open File:") -[[ -n $TARGET ]] && zathura "$DOWNLOAD_DIR/$TARGET" & diff --git a/bin/email b/bin/email deleted file mode 100755 index 84e923e..0000000 --- a/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) -subjects=$(cat $(echo -e ${new_mails/'\n'/' '}) | grep "^Subject: " | sed "s/^Subject: //g") - -if [[ ! -z ${new_mails} ]]; then - /usr/bin/notify-send -t 3 "New mail(s)!" "${subjects}" -fi - -echo "Email last checked on $(date)". diff --git a/bin/i3-shell b/bin/i3-shell deleted file mode 100755 index 120e4b4..0000000 --- a/bin/i3-shell +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -# i3 thread: https://faq.i3wm.org/question/150/how-to-launch-a-terminal-from-here/?answer=152#post-id-152 - -CMD=urxvt -CWD='' - -# Get window ID -ID=$(xdpyinfo | grep focus | cut -f4 -d " ") - -# Get PID of process whose window this is -PID=$(xprop -id $ID | grep -m 1 PID | cut -d " " -f 3) - -# Get last child process (shell, vim, etc) -if [ -n "$PID" ]; then - TREE=$(pstree -lpA $PID | tail -n 1) - PID=$(echo $TREE | awk -F'---' '{print $NF}' | sed -re 's/[^0-9]//g') - - # If we find the working directory, run the command in that directory - if [ -e "/proc/$PID/cwd" ]; then - CWD=$(readlink /proc/$PID/cwd) - fi -fi -if [ -n "$CWD" ]; then - cd $CWD && $CMD -else - $CMD -fi diff --git a/bin/id b/bin/id deleted file mode 100755 index 7dad85d..0000000 --- a/bin/id +++ /dev/null @@ -1,6 +0,0 @@ -#! /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 diff --git a/bin/keyboard b/bin/keyboard deleted file mode 100755 index 5a96bcb..0000000 --- a/bin/keyboard +++ /dev/null @@ -1,36 +0,0 @@ -# Dvorak programer -setxkbmap us -variant dvp - -# Make caps lock a Control -xmodmap -e "clear Lock" -xmodmap -e "keysym Caps_Lock = Control_L Control_L" -xmodmap -e "add Control = Control_L" - -# Remap modifiers (Keyboard dependent) -xmodmap -e "keycode 94 = Mode_switch" -# xmodmap -e 'keycode 108 = Super_L' - -# Remap modifiers (Keyboard independent) -xmodmap -e 'keysym space = Super_L' -xmodmap -e 'keycode any = space' - -# Numbers -xmodmap -e "keysym d = d D 0" -xmodmap -e "keysym o = o O 1" -xmodmap -e "keysym m = m M 1" -xmodmap -e "keysym e = e E 2" -xmodmap -e "keysym w = w W 2" -xmodmap -e "keysym u = u U 3" -xmodmap -e "keysym v = v V 3" -xmodmap -e "keysym h = h H 4" -xmodmap -e "keysym t = t T 5" -xmodmap -e "keysym n = n N 6" -xmodmap -e "keysym g = g G 7" -xmodmap -e "keysym c = c C 8" -xmodmap -e "keysym r = r R 9" - -# Xcape settings -killall -9 xcape - -xcape -e 'Control_L=Escape' -xcape -e 'Super_L=space' diff --git a/bin/mystatus b/bin/mystatus deleted file mode 100755 index b26e9b6..0000000 --- a/bin/mystatus +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -# shell script to prepend i3status with more stuff - -i3status | while : -do - read line - nmails=$(find $HOME/.mail -path '*/new/*' -type f | wc -l) - echo "Email: ${nmails} | $line" || exit 1 -done diff --git a/bin/password b/bin/password deleted file mode 100755 index 065672b..0000000 --- a/bin/password +++ /dev/null @@ -1,2 +0,0 @@ -#! /bin/bash -passmenu diff --git a/bin/recolor b/bin/recolor deleted file mode 100755 index edd5fa5..0000000 --- a/bin/recolor +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -tr -d ' \t' | sed -n ' -s/.*background:/\x1b]11;/p -s/.*foreground:/\x1b]10;/p -s/.*borderColor:/\x1b]708;/p -s/.*color\([0-9][^:]*\):/\x1b]4;\1;/p -' | tr \\n \\a diff --git a/bin/rename_workspace b/bin/rename_workspace deleted file mode 100755 index 7636fd2..0000000 --- a/bin/rename_workspace +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -workspace=$(i3-msg -t get_outputs | grep -Po '"current_workspace":"[^\"]*"' | sed 's/"current_workspace":"\([^"]\+\)"/\1/g') -number=$(echo "${workspace//[!0-9]}") - -new_name=$(zenity --entry --title="Rename workspace" --entry-text "$workspace") -if [[ "$new_name" != *:* ]]; then - new_name="$number:$new_name" -fi - -echo $new_name -exec i3-msg rename workspace to "$new_name" diff --git a/bin/run b/bin/run deleted file mode 100755 index 4b57856..0000000 --- a/bin/run +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -SCRIPTS_DIR="$HOME/dotfiles/bin" && cd $SCRIPTS_DIR -SCRIPTS=$(ls -A $SCRIPTS_DIR) -TARGET=$(echo "${SCRIPTS//"$SCRIPTS_DIR/"/}" | dmenu -i -p "Run script:") -[[ -n $TARGET ]] && "$SCRIPTS_DIR/$TARGET" diff --git a/bin/swap b/bin/swap deleted file mode 100755 index 4c17dc7..0000000 --- a/bin/swap +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/python - -import i3 -outputs = i3.get_outputs() -print(outputs[0]) - -# set current workspace to output 0 -i3.workspace(outputs[0]['current_workspace']) - -# ..and move it to the other output. -# outputs wrap, so the right of the right is left ;) -i3.command('move', 'workspace to output right') - -# rinse and repeat -i3.workspace(outputs[1]['current_workspace']) -i3.command('move', 'workspace to output right') diff --git a/bin/tldr b/bin/tldr deleted file mode 100755 index 2b294c0..0000000 --- a/bin/tldr +++ /dev/null @@ -1,246 +0,0 @@ -#!/bin/bash -# tldr client by Ray Lee, http://github.com/raylee/tldr -# a Sunday afternoon's project, I'm sure there's room for improvement. PRs welcome! - -set -uf -o pipefail - -# initialize globals, sanity check the environment, etc. -config() { - init_term_cmds - - if [ -z $(which curl) ]; then - echo "${red}tldr requires \`curl\` installed in your path$reset" - exit 1 - fi - - configdir=~/.tldr - [ -d ~/.config ] && configdir=~/.config/tldr - - platform=$(get_platform) - base_url="https://raw.githubusercontent.com/tldr-pages/tldr/master/pages" - index_url="http://tldr-pages.github.io/assets/index.json" - index="$configdir/index.json" - cache_days=14 - force_update='' - - #check if config folder exists, otherwise create it - [ -d "$configdir" ] || mkdir -p "$configdir" - - [ ! -f $index ] && update_index - auto_update_index -} - -update_index() { - curl -sf -o "$index" "$index_url" - res=$? - if [ $res -eq 22 ]; then - echo "Could not download index from $index_url" - exit 1 - fi -} - -# if the file exists and is more recent than $cache_days old -recent() { - exists=$(find "$1" -mtime -$cache_days 2>/dev/null) - [ -n "$exists" -a -z "$force_update" ] -} - -auto_update_index() { - recent "$index" || update_index -} - -# function contents via http://mywiki.wooledge.org/BashFAQ/037 -init_term_cmds() { - # only set if we're on an interactive session - [[ -t 2 ]] && { - reset=$( tput sgr0 || tput me ) # Reset cursor - bold=$( tput bold || tput md ) # Start bold - under=$( tput smul || tput us ) # Start underline - italic=$( tput sitm || tput ZH ) # Start italic - eitalic=$( tput ritm || tput ZH ) # End italic - default=$( tput op ) - back=$'\b' - - [[ $TERM != *-m ]] && { - black=$( tput setaf 0 || tput AF 0 ) - red=$( tput setaf 1 || tput AF 1 ) - green=$( tput setaf 2 || tput AF 2 ) - yellow=$( tput setaf 3 || tput AF 3 ) - blue=$( tput setaf 4 || tput AF 4 ) - magenta=$( tput setaf 5 || tput AF 5 ) - cyan=$( tput setaf 6 || tput AF 6 ) - white=$( tput setaf 7 || tput AF 7 ) - - onblue=$( tput setab 4 || tput AB 4 ) - ongrey=$( tput setab 7 || tput AB 7 ) - } - } 2>/dev/null ||: - - # osx's termcap doesn't have italics. The below adds support for iTerm2 - # and is harmless on Terminal.app - [ "$(get_platform)" = "osx" ] && { - italic=$(echo -e "\033[3m") - eitalic=$(echo -e "\033[23m") - } -} - -heading() { - local line="$*" - echo "$bold$red${line:2}$reset" -} - -quotation() { - local line="$*" - echo "$under${line:2}$reset" -} - -list_item() { - local line="$*" - echo "$line$reset" -} - -code() { - local line="$*" - # I'm sure there's a better way to strip the first and last characters. - line="${line:1}" - line="${line%\`}" - # convert {{variable}} to italics - line=${line//\{\{/$italic} - line=${line//\}\}/$eitalic} - - echo "$bold$line$reset" -} - -text() { - local line="$*" - echo "$line" -} - -# an idiot-level recognition of tldr's markdown. Needs improvement, or -# subcontracting out to a markdown -> ANSI formatting command -display_tldr() { - # read one line at a time, don't strip whitespace ('IFS='), and process - # last line even if it doesn't have a newline at the end - while IFS= read -r line || [[ -n "$line" ]]; do - start=${line:0:1} # get the first character - case "$start" in - '#') heading "$line" - ;; - '>') quotation "$line" - ;; - '-') list_item "$line" - ;; - '`') code "$line" - ;; - *) text "$line" - ;; - esac - done -} - -# convert the local platorm name to tldr's version -get_platform() { - case `uname -s` in - Darwin) echo "osx" ;; - Linux) echo "linux" ;; - SunOS) echo "sunos" ;; - *) echo "common" ;; - esac -} - -# extract the platform key from index.json, return preferred subpath to tldrpage -path_for_cmd() { - local desc=$(tr '{' '\n' < $index | grep "\"name\":\"$1\"") - # results in, eg, "name":"netstat","platform":["linux","osx"]}, - - [ -z "$desc" ] && return - - # use the platform specific version of the tldr first - if [[ $desc =~ \"$platform\" ]]; then - echo "$platform/$1.md" - elif [[ $desc =~ \"common\" ]]; then - echo "common/$1.md" - else - # take the first one so we can show something, but warn the user - local p=$(echo "$desc" | cut -d '"' -f 8) - >&2 echo -e "${red}tldr page $1 not found in $platform or common, using page from platform $p instead$reset\n" - echo "$p/$1.md" - fi -} - -# return the local cached copy of the tldrpage, or retrieve and cache from github -get_tldr() { - local p="$(path_for_cmd $1)" - cached="$configdir/$p" - recent "$cached" || { - mkdir -p $(dirname $cached) - curl -sf -o "$cached" "$base_url/$p" - } - # if the curl failed for some reason, keep cat from whinging - cat "$cached" 2>/dev/null -} - - -config - -usage() { - cmd=$(basename $0) - cat < - -[options] - -l, --list: show all available pages - -p, --platform: show page from specific platform rather than autodetecting - -u, --update: update, force retrieving latest copies of locally cached files - -h, -?, --help: this help overview - - - Show examples for this command - -The client caches a copy of all pages and the index locally under -$configdir. By default, the cached copies will expire in $cache_days days. - -EOF -exit 0 -} - -while [ $# -gt 0 ] -do - case "$1" in - -l|--list) - >&2 echo -e "Known tldr pages: \n" - tr '{' '\n' < "$configdir/index.json" | cut -d '"' -f4 | column - exit 0 - ;; - -u|--update) - force_update=yes - update_index - ;; - -h|-\?|--help) - usage - ;; - -p|--platform) - shift - platform=$1 - ;; - -*) - usage - ;; - *) - page=${1:-''} - ;; - esac - shift -done - -[ -z ${page:-} ] && usage - -tldr="$(get_tldr $page)" - -if [ -z "$tldr" ]; then - echo "tldr page for command $page not found" - exit 1 -fi - -display_tldr <<< "$tldr" -echo diff --git a/bin/tmux_attach b/bin/tmux_attach deleted file mode 100755 index 564e3bb..0000000 --- a/bin/tmux_attach +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -SESSIONS=$(tmux list-sessions | cut -d':' -f1) - -SESSION=$(echo "$SESSIONS" | dmenu -i -p "Session:" | tr -d '[[:space:]]') - -[[ -n $SESSION ]] || exit - -urxvt -e zsh -c "tmux new-session -A -s $SESSION" diff --git a/bin/touchpad b/bin/touchpad deleted file mode 100755 index 17649fa..0000000 --- a/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/vimin b/bin/vimin deleted file mode 100755 index 905b30f..0000000 --- a/bin/vimin +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -tempfile=$(mktemp) -urxvt -e vim ${tempfile} -cat ${tempfile} | xclip -i diff --git a/bin/workspace b/bin/workspace deleted file mode 100755 index a22511e..0000000 --- a/bin/workspace +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/zsh - -# Command to use -[[ $1 = 'n' ]] && cmd="workspace" -[[ $1 = 'm' ]] && cmd="move container to workspace" - -# List of workspaces -workspaces=$(i3-msg -t get_workspaces | grep -Po '"name":.*?[^\\]"' | sed 's/"name":"\([^"]\+\)"/\1/g') - -# Keep only the ones containing : -workspaces=$(echo $workspaces | sed '/:/!d') - -# Get desired workspace -target=$(echo $workspaces | dmenu -i -sf green -p "Go to workspace:") - -# Exit if empty -[[ -z $target ]] && exit - -# If new workspace has to be created -if [[ ! $target = [0-9]* ]]; then - - # Calculate number for new workspace - used_numbers=$(echo $workspaces | awk 'BEGIN { FS = ":" } ; { print $1 }') - 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 - - # Add number to workspace name - target=$new_number:$target -fi - -# Execute command -exec i3-msg $cmd $target -- cgit v1.2.3