-
-
Save opennomad/15c4d624dce99066a82d to your computer and use it in GitHub Desktop.
Revisions
-
opennomad revised this gist
Nov 5, 2019 . 1 changed file with 7 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -59,6 +59,9 @@ case ${MENU_ENGINE} in 'zenity') MENU_ARGS=${ZENITY_ARGS} ;; 'rofi') MENU_ARGS=${ROFI_ARGS} ;; *) echo "incorrecty MENU_ENGINE: ${MENU_ENGINE} for snippy" exit 1 @@ -71,8 +74,8 @@ esac # fetches a document and interprets bashsyntax in string (bashdown) templates # @param string - string with bash(down) syntax (usually surrounded by ' quotes instead of ") bashdown(){ while read -r line; do line="$(eval "printf -- \"$( printf -- "%s" "$line" | sed 's/"/\\"/g')\"")"; echo -e "$line" done < <(cat "${DIR}/${FILE}") } @@ -96,14 +99,15 @@ run(){ cd "${DIR}" # Use the filenames in the snippy directory as menu entries. # Get the menu selection from the user. FILE=$(find -L . -type f | sort | grep -v '^\.$' | sed 's!\.\/!!' | ${MENU_ENGINE} ${MENU_ARGS}) # FILE=$(find -L . -type f | grep -v '^\.$' | sed 's!\.\/!!' | zenity ) # just return if nothing was selected [[ -z "${FILE}" ]] && return 1 if [ -f "${DIR}/${FILE}" ]; then # Put the contents of the selected file into the paste buffer. content="$(bashdown < "${DIR}/${FILE}")" echo "::::${content}::::" if [[ "${#content}" == 0 ]]; then printf "%s" "${FILE}" > $TMPFILE else -
opennomad revised this gist
Jul 9, 2016 . 1 changed file with 40 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,12 @@ #!/usr/bin/env bash # video demo at: http://www.youtube.com/watch?v=90xoathBYfk # augmented by "opennomad": https://gist.github.com/opennomad/15c4d624dce99066a82d # originally written by "mhwombat": https://bbs.archlinux.org/viewtopic.php?id=71938&p=2 # Based on "snippy" by "sessy" # (https://bbs.archlinux.org/viewtopic.php?id=71938) # # You will also need "dmenu", "zenity", "xsel" and "xdotool". Get them from your linux # distro in the usual way. # # To use: @@ -27,14 +28,42 @@ # TIP: If you're using XMonad, add something like this to xmonad.hs # ((mod4Mask, xK_s), spawn "/path/to/snippy") # # 4. Set variables in ~/.snippy.conf. for example # MENU_ENGINE="dmenu" # DMENU_ARGS=' -p snippy -fn arial -sf green' # ZENITY_ARGS='--list --hide-header --column=Snippet --text=snippy' # GUIPASTE="xdotool key ctrl+v" # CLIPASTE="xdotool key ctrl+shift+v" CONFIG=${HOME}/.snippy.conf APPS="xdotool xsel dmenu zenity" DIR=${HOME}/.snippy MENU_ENGINE="dmenu" DMENU_ARGS='-b' ZENITY_ARGS='--list --hide-header --column=Snippet --text=snippy' # if nothing happens, try "xdotool click 2", "xdotool key ctrl+v" or "xdotool key ctrl+shift+v" GUIPASTE="xdotool key ctrl+v" CLIPASTE="xdotool key ctrl+shift+v" TMPFILE="/tmp/.snippy.tmp"; :>$TMPFILE # source the config file if it exists [[ -f ${CONFIG} ]] && source ${CONFIG} # set the menu options depending on the engine case ${MENU_ENGINE} in 'dmenu') MENU_ARGS=${DMENU_ARGS} ;; 'zenity') MENU_ARGS=${ZENITY_ARGS} ;; *) echo "incorrecty MENU_ENGINE: ${MENU_ENGINE} for snippy" exit 1 esac # smarty like template engine which executes inline bash in (bashdown) strings (replaces variables with values e.g.) # @link http://github.com/coderofsalvation/bashdown # @dependancies: sed cat @@ -50,7 +79,7 @@ bashdown(){ init(){ for APP in $APPS; do command -v "$APP" &>/dev/null || { read -p "install the following required utils? : $APPS (y/n)" reply [[ "$reply" == "y" ]] && sudo apt-get install "${APPS}"; } @@ -67,7 +96,11 @@ run(){ cd "${DIR}" # Use the filenames in the snippy directory as menu entries. # Get the menu selection from the user. FILE=$(find -L . -type f | grep -v '^\.$' | sed 's!\.\/!!' | ${MENU_ENGINE} ${MENU_ARGS}) # FILE=$(find -L . -type f | grep -v '^\.$' | sed 's!\.\/!!' | zenity ) # just return if nothing was selected [[ -z "${FILE}" ]] && return 1 if [ -f "${DIR}/${FILE}" ]; then # Put the contents of the selected file into the paste buffer. content="$(bashdown < "${DIR}/${FILE}")" -
opennomad revised this gist
Jul 23, 2015 . No changes.There are no files selected for viewing
-
opennomad revised this gist
Jul 23, 2015 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ #!/usr/bin/env bash # video demo at: http://www.youtube.com/watch?v=90xoathBYfk # written by "mhwombat": https://bbs.archlinux.org/viewtopic.php?id=71938&p=2 @@ -81,7 +81,7 @@ run(){ fi xsel -b --input < $TMPFILE # Paste into the current application. if is_window; then ${GUIPASTE} else ${CLIPASTE} @@ -90,8 +90,7 @@ run(){ is_window(){ name="$(xdotool getwindowname "$(xdotool getwindowfocus)" | tr '[:upper:]' '[:lower:]')" [[ "$name" =~ term|tilda|@${HOSTNAME} ]] && return 1 return 0 } -
opennomad revised this gist
Jun 25, 2015 . 1 changed file with 49 additions and 43 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ # video demo at: http://www.youtube.com/watch?v=90xoathBYfk # written by "mhwombat": https://bbs.archlinux.org/viewtopic.php?id=71938&p=2 # Based on "snippy" by "sessy" # (https://bbs.archlinux.org/viewtopic.php?id=71938) # # You will also need "dmenu", "xsel" and "xdotool". Get them from your linux @@ -13,12 +13,12 @@ # # 2. Create a file in that directory for each snippet that you want. # The filename will be used as a menu item, so you might want to # omit the file extension when you name the file. # # TIP: If you have a lot of snippets, you can organise them into # subdirectories under ~/.snippy. # # TIP: The contents of the file will be pasted asis, so if you # don't want a newline at the end when the text is pasted, don't # put one in the file. # @@ -32,61 +32,67 @@ APPS="xdotool xsel dmenu" DMENU_ARGS="-b" TMPFILE="/tmp/.snippy.tmp"; :>$TMPFILE # if nothing happens, try "xdotool click 2", "xdotool key ctrl+v" or "xdotool key ctrl+shift+v" GUIPASTE="xdotool key ctrl+v" CLIPASTE="xdotool key ctrl+shift+v" # smarty like template engine which executes inline bash in (bashdown) strings (replaces variables with values e.g.) # @link http://github.com/coderofsalvation/bashdown # @dependancies: sed cat # @example: echo 'hi $NAME it is $(date)' | bashdown # fetches a document and interprets bashsyntax in string (bashdown) templates # @param string - string with bash(down) syntax (usually surrounded by ' quotes instead of ") bashdown(){ while read line; do line="$(eval "printf \"$( printf "%s" "$line" | sed 's/"/\\"/g')\"")"; echo -e "$line" done < <(cat "${DIR}/${FILE}") } init(){ for APP in $APPS; do which "$APP" &>/dev/null || { read -p "install the following required utils? : $APPS (y/n)" reply [[ "$reply" == "y" ]] && sudo apt-get install "${APPS}"; } done [[ ! -d "$DIR" ]] && { echo -e "created $DIR\n"; mkdir "$DIR"; printf "hi it is \$(date)" > "$DIR/test"; } return 0 } run(){ cd "${DIR}" # Use the filenames in the snippy directory as menu entries. # Get the menu selection from the user. FILE=$(find -L . -type f | grep -v '^\.$' | sed 's!\.\/!!' | /usr/bin/dmenu ${DMENU_ARGS}) if [ -f "${DIR}/${FILE}" ]; then # Put the contents of the selected file into the paste buffer. content="$(bashdown < "${DIR}/${FILE}")" if [[ "${#content}" == 0 ]]; then printf "%s" "${FILE}" > $TMPFILE else printf "%s" "$content" > $TMPFILE fi else ${FILE} &> $TMPFILE # execute as bashcommand fi xsel -b --input < $TMPFILE # Paste into the current application. if [[ $(is_window) ]]; then ${GUIPASTE} else ${CLIPASTE} fi } is_window(){ name="$(xdotool getwindowname "$(xdotool getwindowfocus)" | tr '[:upper:]' '[:lower:]')" echo "$name" > ~/tmp/foo [[ ! "$name" =~ term|tilda|@${HOSTNAME} ]] && return 1 return 0 } init && run -
coderofsalvation revised this gist
Mar 23, 2015 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -33,6 +33,7 @@ DMENU_ARGS="-b" TMPFILE="/tmp/.snippy.tmp"; :>$TMPFILE # if nothing happens, try "xdotool click 2", "xdotool key ctrl+v" or "xdotool key ctrl+shift+v" GUIPASTE="xdotool click 2" CLIPASTE="xdotool key ctrl+v" # smarty like template engine which executes inline bash in (bashdown) strings (replaces variables with values e.g.) # @link http://github.com/coderofsalvation/bashdown @@ -78,15 +79,14 @@ run(){ fi xsel --input < $TMPFILE # Paste into the current application. [[ is_window ]] && ${GUIPASTE} || ${CLIPASTE} # cli or gui paste } is_window(){ name="$(xdotool getwindowname $(xdotool getwindowfocus) | tr '[:upper:]' '[:lower:]')" [[ ! "$name" =~ term|tilda ]] && return 1 return 0 } init && run -
coderofsalvation revised this gist
Mar 5, 2015 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -71,7 +71,8 @@ run(){ FILE=`find -L . -type f | grep -v '^\.$' | sed 's!\.\/!!' | /usr/bin/dmenu ${DMENU_ARGS}` if [ -f ${DIR}/${FILE} ]; then # Put the contents of the selected file into the paste buffer. content="$(cat ${DIR}/${FILE} | bashdown)" [[ "${#content}" == 0 ]] && printf "${FILE}" > $TMPFILE || printf "%s" "$content" > $TMPFILE else ${FILE} &> $TMPFILE # execute as bashcommand fi @@ -88,3 +89,4 @@ paste_cli(){ } init && run -
coderofsalvation revised this gist
Dec 16, 2014 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -31,6 +31,8 @@ DIR=${HOME}/.snippy APPS="xdotool xsel dmenu" DMENU_ARGS="-b" TMPFILE="/tmp/.snippy.tmp"; :>$TMPFILE # if nothing happens, try "xdotool click 2", "xdotool key ctrl+v" or "xdotool key ctrl+shift+v" GUIPASTE="xdotool click 2" # smarty like template engine which executes inline bash in (bashdown) strings (replaces variables with values e.g.) # @link http://github.com/coderofsalvation/bashdown @@ -75,14 +77,14 @@ run(){ fi xsel --input < $TMPFILE # Paste into the current application. paste_cli || ${GUIPASTE} # cli or gui paste } paste_cli(){ name="$(xdotool getwindowname $(xdotool getwindowfocus) | tr '[:upper:]' '[:lower:]')" [[ ! "$name" =~ term|tilda ]] && return 1 ${GUIPASTE} } init && run -
coderofsalvation revised this gist
Dec 9, 2014 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,6 @@ DIR=${HOME}/.snippy APPS="xdotool xsel dmenu" DMENU_ARGS="-b" TMPFILE="/tmp/.snippy.tmp"; :>$TMPFILE # smarty like template engine which executes inline bash in (bashdown) strings (replaces variables with values e.g.) # @link http://github.com/coderofsalvation/bashdown @@ -74,15 +73,16 @@ run(){ else ${FILE} &> $TMPFILE # execute as bashcommand fi xsel --input < $TMPFILE # Paste into the current application. paste_cli || xdotool key ctrl+v # cli or gui paste } paste_cli(){ name="$(xdotool getwindowname $(xdotool getwindowfocus) | tr '[:upper:]' '[:lower:]')" [[ ! "$name" =~ term|tilda ]] && return 1 [[ "$name" =~ xterm$ ]] && xdotool click 2 || xdotool key ctrl+shift+v } init && run -
coderofsalvation revised this gist
Dec 2, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -67,7 +67,7 @@ run(){ cd ${DIR} # Use the filenames in the snippy directory as menu entries. # Get the menu selection from the user. FILE=`find -L . -type f | grep -v '^\.$' | sed 's!\.\/!!' | /usr/bin/dmenu ${DMENU_ARGS}` if [ -f ${DIR}/${FILE} ]; then # Put the contents of the selected file into the paste buffer. cat ${DIR}/${FILE} | bashdown > $TMPFILE -
coderofsalvation revised this gist
Nov 14, 2014 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,7 @@ DIR=${HOME}/.snippy APPS="xdotool xsel dmenu" DMENU_ARGS="-b" TMPFILE="/tmp/.snippy.tmp"; :>$TMPFILE XSEL_ARGS="--clipboard --input" # smarty like template engine which executes inline bash in (bashdown) strings (replaces variables with values e.g.) @@ -71,10 +71,12 @@ run(){ if [ -f ${DIR}/${FILE} ]; then # Put the contents of the selected file into the paste buffer. cat ${DIR}/${FILE} | bashdown > $TMPFILE else ${FILE} &> $TMPFILE # execute as bashcommand fi xsel ${XSEL_ARGS} < $TMPFILE # Paste into the current application. is_terminal && xdotool key ctrl+shift+v || xdotool key ctrl+v # cli or gui paste } is_terminal(){ -
coderofsalvation revised this gist
Nov 10, 2014 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -73,9 +73,14 @@ run(){ cat ${DIR}/${FILE} | bashdown > $TMPFILE xsel ${XSEL_ARGS} < $TMPFILE # Paste into the current application. is_terminal && xdotool key ctrl+shift+v || xdotool key ctrl+v # cli or gui paste fi } is_terminal(){ name="$(xdotool getwindowname $(xdotool getwindowfocus) | tr '[:upper:]' '[:lower:]')" [[ "$name" =~ term|tilda ]] && return 0 || return 1 } init && run -
coderofsalvation revised this gist
Nov 1, 2014 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -40,9 +40,11 @@ XSEL_ARGS="--clipboard --input" # fetches a document and interprets bashsyntax in string (bashdown) templates # @param string - string with bash(down) syntax (usually surrounded by ' quotes instead of ") bashdown(){ txt="$(cat - )"; lines="$(cat ${DIR}/${FILE} | wc -l )" (( lines > 1 )) && enter="\n" || enter="" IFS=''; echo "$txt" | while read line; do [[ "$line" =~ '$' ]] && line="$(eval "printf \"$( printf "%s" "$line" | sed 's/"/\\"/g')\"")"; printf "$line""$enter" done } -
coderofsalvation revised this gist
Oct 30, 2014 . 1 changed file with 9 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,12 +5,13 @@ # Based on "snippy" by "sessy" # (https://bbs.archlinux.org/viewtopic.php?id=71938) # # You will also need "dmenu", "xsel" and "xdotool". Get them from your linux # distro in the usual way. # # To use: # 1. Create the directory ~/.snippy # # 2. Create a file in that directory for each snippet that you want. # The filename will be used as a menu item, so you might want to # omit the file extension when you name the file. # @@ -24,7 +25,7 @@ # 3. Bind a convenient key combination to this script. # # TIP: If you're using XMonad, add something like this to xmonad.hs # ((mod4Mask, xK_s), spawn "/path/to/snippy") # DIR=${HOME}/.snippy APPS="xdotool xsel dmenu" @@ -40,8 +41,8 @@ XSEL_ARGS="--clipboard --input" # @param string - string with bash(down) syntax (usually surrounded by ' quotes instead of ") bashdown(){ IFS=''; cat - | while read line; do [[ "$line" =~ '$' ]] && line="$(eval "printf \"$( printf "%s" "$line" | sed 's/"/\\"/g')\"")"; printf "$line" done } @@ -75,3 +76,4 @@ run(){ } init && run -
coderofsalvation revised this gist
Oct 30, 2014 . 1 changed file with 5 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,13 +5,12 @@ # Based on "snippy" by "sessy" # (https://bbs.archlinux.org/viewtopic.php?id=71938) # # You will also need "dmenu", "xsel" and "xdotool", it will be installed # automatically when using debianbased distros (ubuntu). # # To use: # 1. run snippy # 2. Create a file in ~/.snippy for each snippet that you want. # The filename will be used as a menu item, so you might want to # omit the file extension when you name the file. # @@ -25,7 +24,7 @@ # 3. Bind a convenient key combination to this script. # # TIP: If you're using XMonad, add something like this to xmonad.hs # ((mod4Mask, xK_s), spawn "/path/to/snippy"). In XFCE its Settings->Keyboard->Shortcuts # DIR=${HOME}/.snippy APPS="xdotool xsel dmenu" -
coderofsalvation created this gist
Oct 30, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,78 @@ #!/bin/bash # video demo at: http://www.youtube.com/watch?v=90xoathBYfk # written by "mhwombat": https://bbs.archlinux.org/viewtopic.php?id=71938&p=2 # Based on "snippy" by "sessy" # (https://bbs.archlinux.org/viewtopic.php?id=71938) # # You will also need "dmenu", "xsel" and "xdotool". Get them from your linux # distro in the usual way. # # To use: # 1. Create the directory ~/.snippy # # 2. Create a file in that directory for each snippet that you want. # The filename will be used as a menu item, so you might want to # omit the file extension when you name the file. # # TIP: If you have a lot of snippets, you can organise them into # subdirectories under ~/.snippy. # # TIP: The contents of the file will be pasted asis, so if you # don't want a newline at the end when the text is pasted, don't # put one in the file. # # 3. Bind a convenient key combination to this script. # # TIP: If you're using XMonad, add something like this to xmonad.hs # ((mod4Mask, xK_s), spawn "/path/to/snippy") # DIR=${HOME}/.snippy APPS="xdotool xsel dmenu" DMENU_ARGS="-b" TMPFILE="/tmp/.snippy.tmp" XSEL_ARGS="--clipboard --input" # smarty like template engine which executes inline bash in (bashdown) strings (replaces variables with values e.g.) # @link http://github.com/coderofsalvation/bashdown # @dependancies: sed cat # @example: echo 'hi $NAME it is $(date)' | bashdown # fetches a document and interprets bashsyntax in string (bashdown) templates # @param string - string with bash(down) syntax (usually surrounded by ' quotes instead of ") bashdown(){ IFS=''; cat - | while read line; do [[ "$line" =~ '$' ]] && line="$(eval "echo \"$( echo "$line" | sed 's/"/\\"/g')\"")"; echo "$line" done } init(){ for APP in $APPS; do which $APP &>/dev/null || { read -p "install the following required utils? : $APPS (y/n)" reply [[ "$reply" == "y" ]] && sudo apt-get install ${APPS}; } done [[ ! -d "$DIR" ]] && { echo -e "created $DIR\n"; mkdir "$DIR"; printf 'hi it is $(date)' > "$DIR""/test"; } return 0 } run(){ cd ${DIR} # Use the filenames in the snippy directory as menu entries. # Get the menu selection from the user. FILE=`find . -type f | grep -v '^\.$' | sed 's!\.\/!!' | /usr/bin/dmenu ${DMENU_ARGS}` if [ -f ${DIR}/${FILE} ]; then # Put the contents of the selected file into the paste buffer. cat ${DIR}/${FILE} | bashdown > $TMPFILE xsel ${XSEL_ARGS} < $TMPFILE # Paste into the current application. [[ -t 0 ]] && xdotool key ctrl+shift+v || xdotool key ctrl+v # cli or gui paste fi } init && run