Full Code of ganifladi/blurme for AI

master 73453d5e922c cached
2 files
9.6 KB
2.9k tokens
1 requests
Download .txt
Repository: ganifladi/blurme
Branch: master
Commit: 73453d5e922c
Files: 2
Total size: 9.6 KB

Directory structure:
gitextract_s1y57870/

├── README.md
└── blurme

================================================
FILE CONTENTS
================================================

================================================
FILE: README.md
================================================
# blurme

<p>blurme v1.0 Codename MEH (My Eyes Hurt) is a small script which will blur your feh set background if any window, or rofi is open. Furthermore there are some options, which allow you to change the default behaviour a bit. Read more about the options down below.</p>
<p>Please feel free to fork it, make pull requests and use it in your own projects.</p>
<p>This is my first project i publish. Please be gentle on me :)</p>
<h2>How to start</h2>
<h3>Requirements</h3>
<ol>
<li><b>wmctrl</b>: This script makes use of wmctrl to get the current workspace number and to clarify, whether any window is open. It's essential!</li>
<li><b>feh</b>: Furthermore you'll need feh to set your background image(s).</li>
<li><b>imagemagick</b>: And last but not least imagemagick is mandatory to blur the images</li>
</ol>
<h3>Download and ...</h3>
<ol>
    <li>Place it anywhere you like (e.g. ~/.scripts)</li>
    <li>Make it executable (chmod +x ~/.scripts/blurme)</li>
</ol>
<h2>How to run it</h2>
<h3>Manual start</h3>
<p>Run it once in a terminal of your choice with ~/.scripts/blurme</p>
<h3>Autostart</h3>
<h4>i3</h4>
<p>Add the line "exec --no-startup-id ~/.scripts/blurme &" to your i3 config.</p>
<h4>bspwm</h4>
<p>Add the line "sh ~/.scripts/blurme &" to ~/.xinitrc</p>
<h4>openbox</h4>
<p>Add the line "sh ~/.scripts/blurme &" to ~/.config/openbox/autostart</p>
<h3>Options</h3>
<p>There are several optional arguments provided that may be used. These include:</p>
<ul>
    <li><b>-a</b>: Add another program (process name), which will start the blur effect</li>
    <li><b>-c</b>: set custom directory for transition images (default: ~/.cache/blurme)</li>
    <li><b>-d</b>: Set custom directory (default: ~/.local/share/blurme)</li>
    <li><b>-t</b>: Set custom transition time in sec (default: 0.01)</li>
    <li><b>-v</b>: Show additional output (verbose)</li>
    <li><b>-h</b>: Show all these parameters</li>
</ul>


================================================
FILE: blurme
================================================
#!/bin/bash

# Error Prevention: Multiple Instances ----------------------------------

if [[ $(pgrep -cl blurme) > 1 ]]; then
    echo 'BLURME: Another instance of blurme me is already running.'
    echo '        Please kill it with fire (pkill blurme) first, then try running me again.'
    exit
fi



# Options ---------------------------------------------------------------

while getopts :a:c:d:t:vh option; do
    case "${option}" in
        a) ADDBLUR=${OPTARG};;
        c) CACHEDIR=${OPTARG};;
        d) WORKINGDIR=${OPTARG};;
        t) TIME=${OPTARG};;
        v) VERBOSE=true;;
        h)
            echo '---------------------------------------'
            echo 'BLURME v1.0 Codename MEH (My Eyes Hurt)'
            echo '---------------------------------------'
            echo "Options:  '-a' adds one additional program, which will start the blur effect (must be process name!)" 1>&2
            echo "          '-c' set custom directory for transition images (default: ~/.cache/blurme)" 1>&2
            echo "          '-d' set custom directory (default: ~/.cache/blurme)" 1>&2
            echo "          '-t' set custom transition time in sec (default: 0.01)" 1>&2
            echo "          '-v' set verbose true" 1>&2
            exit
            ;;
        \?)
            echo 'BLURME: Invalid option! Please use as shown below:' 1>&2
            echo "        '-a' adds one additional program, which will start the blur effect (must be process name!)" 1>&2
            echo "        '-c' set custom directory for transition images (default: ~/.cache/blurme)" 1>&2
            echo "        '-d' set custom directory (default: ~/.cache/blurme)" 1>&2
            echo "        '-t' set custom transition time in sec (default: 0.01)" 1>&2
            echo "        '-v' set verbose true" 1>&2
            exit
            ;;
        :) echo "BLURME: '-$OPTARG' requires an argument" 1>&2; exit;;
    esac
done
shift $((OPTIND-1))

if [ "$VERBOSE" = true ]; then
    echo '---------------------------------------'
    echo 'BLURME v1.0 Codename MEH (My Eyes Hurt)'
    echo '---------------------------------------'
fi



# Variables -------------------------------------------------------------

# Working directory contains a copy of the original unblured image,
# and its path.
if [ -z "$WORKINGDIR" ]; then WORKINGDIR=/home/$USER/.local/share/blurme; fi
if ! [ -d $WORKINGDIR ]; then mkdir $WORKINGDIR; fi
if [ "$VERBOSE" = true ]; then echo 'BLURME: Workingdir is set to '$WORKINGDIR; fi

# Cache directory contains all blurry rendered transition images.
if [ -z "$CACHEDIR" ]; then CACHEDIR=/home/$USER/.cache/blurme; fi
if ! [ -d $CACHEDIR ]; then mkdir $CACHEDIR; fi
if [ "$VERBOSE" = true ]; then echo 'BLURME: Cache (contains transition images) is set to '$CACHEDIR; fi


# Error Prevention: Blurry startup
#
# Check if background is set to not blurred on start.
# If for some reason the script wasn't terminated correctly,
# the background might be still blurry, and the logic will go crazy.
# This only fix only works when the workingdir and its containing
# copy of the original not blurred background still exist
# after reboot (no temp directory!).
if [[ $(tail -n1 ~/.fehbg | cut -d "'" -f2) = "$CACHEDIR/trans-9" ]]; then
    # Reset wallpaper to original one
    feh --bg-fill $(cat "$WORKINGDIR/original-bg")
fi


if [ -z "$TIME" ]; then TIME=0.01; fi
#echo "Transition time is set to: "$TIME

CURRWORKSPACE=$(wmctrl -d | grep '*' | cut -d ' ' -f1)
#echo "Current workspace: $CURRWORKSPACE"

OPENWINDOWS=$(wmctrl -l | cut -d ' ' -f3 | grep $CURRWORKSPACE | wc -l)
#echo "Open windows on workspace$CURRWORKSPACE: $WINDOWS"

CURRWALLPAPER=$(tail -n1 ~/.fehbg | cut -d "'" -f2)
#echo "Wallpaper path: $CURRWALLPAPER"

ORIGINAL=$WORKINGDIR/original-bg
echo $CURRWALLPAPER > $ORIGINAL

COPYBG=$WORKINGDIR/copied-bg
cp $(cat $ORIGINAL) $COPYBG






# Functions -------------------------------------------------------------

function create_images {

    if [ "$VERBOSE" = true ]; then echo 'BLURME: Create transition images ...'; fi

    local i="0"

    while [ $i -lt "10" ]; do
        A=$(echo "($i + 1) * 2.4" | bc -l)
        B=$(echo "($i + 1) * 1.2" | bc -l)
        convert $COPYBG -blur $A,$B $CACHEDIR/trans-$i
        local PERC=$(echo "($i+1) * 10" | bc -l)
        if [ "$VERBOSE" = true ]; then echo 'BLURME: '$PERC'%'; fi
        i=$[$i+1]
    done

    if [ "$VERBOSE" = true ]; then echo 'BLURME: Done!'; fi
}

function transinit {

    local REF=$CACHEDIR/trans-0
    local CMP=/tmp/blurme-trans-0.tmp

    if [ "$VERBOSE" = true ]; then
        echo "BLURME: Huh?! Background is not blurred, let's fix that!"
        echo 'BLURME: Unblurred original wallpaper is '$(cat $ORIGINAL)
    fi

    # is it really necessary to render again
    if [ -f $REF ]; then
        convert $(cat $ORIGINAL) -blur 2.4,1.2 $CMP
        # create new transition images if newly created trans-0 and old trans-0 are not the same
        if ! cmp -s $CMP $REF; then
            if [ "$VERBOSE" = true ]; then echo 'BLURME: Seems like we have a new wallpaper which needs to be rendered.'; fi
            rm $CMP
            create_images
        else
            if [ "$VERBOSE" = true ]; then echo 'BLURME: This background seems familiar. No need to render it again! :)'; fi
            rm $CMP
        fi
    else
        # reference file not found inside existing working dir ... better render them, to get things working
        if [ "$VERBOSE" = true ]; then echo "BLURME: Could'nt find transition images in cachedir. Will create them on the fly."; fi
        create_images
    fi
}

function transition {

    if [ "$VERBOSE" = true ]; then echo 'BLURME: Blur wallpaper ...'; fi

    local j="0"

    while [ $j -lt "10" ]; do
        feh --bg-fill $CACHEDIR/trans-$j
        local PERC=$(echo "($j+1) * 10" | bc -l)
        if [ "$VERBOSE" = true ]; then echo 'BLURME: '$PERC'%'; fi
        j=$[$j+1]
        sleep $TIME
    done
    if [ "$VERBOSE" = true ]; then echo 'BLURME: Done!'; fi
}

function transition_rev {

    if [ "$VERBOSE" = true ]; then echo 'BLURME: Unblur wallpaper ...'; fi

    local j="9"

    while [ $j -ge "0" ]; do
        feh --bg-fill $CACHEDIR/trans-$j
        local PERC=$(echo "($j+1) * 10" | bc -l)
        if [ "$VERBOSE" = true ]; then echo 'BLURME: '$PERC'%'; fi
        j=$[$j-1]
        sleep $TIME
    done

    feh --bg-fill $(cat $ORIGINAL)
    if [ "$VERBOSE" = true ]; then echo 'BLURME: Done!'; fi
}

function finish {
    feh --bg-fill $(cat $ORIGINAL)
    exit
}


# Logic ------------------------------------------------------------------

trap finish EXIT
trap finish SIGHUP
trap finish SIGINT
trap finish SIGKILL
trap finish SIGTERM

transinit

while true; do

    CURRWORKSPACE=$(wmctrl -d | grep '*' | cut -d ' ' -f1)
    OPENWINDOWS=$(wmctrl -l | cut -d ' ' -f3 | grep $CURRWORKSPACE | wc -l)
    CURRWALLPAPER=$(tail -n1 ~/.fehbg | cut -d "'" -f2)

    # is any window or rofi open on current workspace
    if [[ $OPENWINDOWS > 0 ]] || [[ $(pgrep -cl rofi) > 0 ]]  || [[ $(pidof $ADDBLUR) > 0 ]]; then
        # is wallpaper not blurred
        if [ "$CURRWALLPAPER" != "$CACHEDIR/trans-9" ]; then
            # has wallpaper been changed
            if [ "$CURRWALLPAPER" != "$(cat $ORIGINAL)" ]; then
                # save current wallpapers path
                echo $CURRWALLPAPER > $ORIGINAL
                # copy current wallpaper as reference
                cp $(cat $ORIGINAL) $COPYBG
                # create transition images
                transinit
            fi
            # set wallpapers to blur
            transition
        fi
    else
        # no windows or rofi open and wallpaper is not the unblurred original
        if [ "$CURRWALLPAPER" != "$(cat $ORIGINAL)" ]; then
            # unblur and set to original wallpaper
            transition_rev
        fi
    fi

    sleep 0.5
done
Download .txt
gitextract_s1y57870/

├── README.md
└── blurme
Condensed preview — 2 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (10K chars).
[
  {
    "path": "README.md",
    "chars": 1932,
    "preview": "# blurme\n\n<p>blurme v1.0 Codename MEH (My Eyes Hurt) is a small script which will blur your feh set background if any wi"
  },
  {
    "path": "blurme",
    "chars": 7911,
    "preview": "#!/bin/bash\n\n# Error Prevention: Multiple Instances ----------------------------------\n\nif [[ $(pgrep -cl blurme) > 1 ]]"
  }
]

About this extraction

This page contains the full source code of the ganifladi/blurme GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 2 files (9.6 KB), approximately 2.9k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!