CrunchBang Linux Pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

CrunchBang Linux Pastebin

Posted by Josh on Fri 26th Nov 02:52 (modification of post by corenominal view diff)
diff | download | new post

  1. #!/bin/bash
  2. # Author:
  3. #   Philip Newborough <corenominal@corenominal.org>
  4. # Copyright:
  5. #   © 2008 Philip Newborough <corenominal@corenominal.org>
  6. # License:
  7. #   This program is free software; you can redistribute it and/or
  8. #   modify it under the terms of the GNU Lesser General Public
  9. #   License as published by the Free Software Foundation; either
  10. #   version 2.1 of the License, or (at your option) any later version.
  11. #
  12. #   This program is distributed in the hope that it will be useful,
  13. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. #   Lesser General Public License for more details.
  16. #
  17. #   You should have received a copy of the GNU Lesser General Public
  18. #   License along with this library; if not, write to the Free Software
  19. #   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  20. #
  21. #   On Debian systems, the complete text of the GNU Lesser General Public
  22. #   License V2.1 can be found in the file `/usr/share/common-licenses/LGPL-2.1'.
  23. #-------------------------------------------------------------------------------   
  24. # Display help
  25. if [ "$1" = "" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  26.     echo "Usage:"
  27.     echo "  rotate-wallpaper --path DIRECTORY"
  28.     echo ""
  29.     echo "    -h, --help"
  30.     echo "          Shows this message and exits."
  31.     echo "    -p, --path"
  32.     echo "          Set path to directory containing images."
  33.     echo ""
  34.     exit   
  35. fi
  36. if [ "$1" = "-p" ] || [ "$1" = "--path" ];then
  37.     if [ ! "$2" = "" ];then
  38.         # Set the path to your wallpaper directory
  39.         WALLPAPERS=$2
  40.         # Sanity check. Does wallpaper directory exist
  41.         if [ ! -d $WALLPAPERS ]; then
  42.             echo "Oops! Specified directory does not exist."
  43.             echo ""
  44.             rotate-wallpaper --help
  45.             exit 1
  46.         fi
  47.         # the sanity check for files at all is unecessary because of this next part
  48.         # Sanity check. Is wallpapers directory empty of images?
  49.         # + Build query
  50.         QUERY=""
  51.         if [ "$(ls $WALLPAPERS/*.jpg 2> /dev/null)" ]; then
  52.             QUERY="$QUERY$WALLPAPERS/*.jpg "
  53.         fi
  54.         if [ "$(ls $WALLPAPERS/*.JPG 2> /dev/null)" ]; then
  55.             QUERY="$QUERY$WALLPAPERS/*.JPG "
  56.         fi
  57.         if [ "$(ls -l $WALLPAPERS/*.PNG 2> /dev/null)" ]; then
  58.             QUERY="$QUERY$WALLPAPERS/*.PNG "
  59.         fi
  60.         if [ "$(ls -l $WALLPAPERS/*.png 2> /dev/null)" ]; then
  61.             QUERY="$QUERY$WALLPAPERS/*.png "
  62.         fi
  63.         if [ "$QUERY" = "" ];then
  64.             echo "Oops! No images found within specified directory."
  65.             echo ""
  66.             rotate-wallpaper --help
  67.             exit 1
  68.         fi
  69.         # Sanity check. Does config directory exist?
  70.         if [ ! -d ~/.config/rotate-wallpaper ]; then
  71.             mkdir ~/.config/rotate-wallpaper
  72.         fi
  73.         # Sanity check. Does config file exist?
  74.         if [ ! -f ~/.config/rotate-wallpaper/count ]; then
  75.             touch ~/.config/rotate-wallpaper/count
  76.             echo "0" > ~/.config/rotate-wallpaper/count
  77.         fi
  78.         # Count number of wallpapers
  79.         NO_OF_WALLPAPERS=0
  80.         for file in $QUERY; do
  81.             if [ ! -d "$file" ];then
  82.                 NO_OF_WALLPAPERS=$(( NO_OF_WALLPAPERS+1 ))
  83.             fi
  84.         done
  85.         # Read in number of last wallpaper displayed, or start from 1
  86.         PREVIOUS_WALLPAPER="$(cat ~/.config/rotate-wallpaper/count)"
  87.         NEW_WALLPAPER=$(( PREVIOUS_WALLPAPER+1 ))
  88.         # Do we need to loop back to 1?
  89.         if [ $NEW_WALLPAPER -gt $NO_OF_WALLPAPERS ];then
  90.             NEW_WALLPAPER=1
  91.         fi
  92.         # Set wallpaper
  93.         CNT=1
  94.         for file in $QUERY; do
  95.             if [ $CNT = $NEW_WALLPAPER ]; then
  96.                 if [ ! -d "$file" ];then
  97.                     FILE_TYPE=$(file -i "$file")
  98.                     if [ "$FILE_TYPE" = "$file: image/png" ] || \
  99.                     [ "$FILE_TYPE" = "$file: image/jpeg" ];then
  100.                         nitrogen --set-scaled "$file"
  101.                     fi
  102.                 fi
  103.             fi
  104.             CNT=$(( CNT+1 ))
  105.         done
  106.         # Save count and exit
  107.         echo "$NEW_WALLPAPER" > ~/.config/rotate-wallpaper/count
  108.         exit
  109.     else
  110.         # Show error if no directory given
  111.         echo "Oops! Image directory not specified."
  112.         echo ""
  113.         rotate-wallpaper --help
  114.         exit 1
  115.     fi
  116. fi
  117. # If all else fails
  118. echo "Oops! Invalid command. Have a clue..."
  119. rotate-wallpaper --help
  120. exit 1

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me