diff --git a/bin/po.sh b/bin/po.sh index 721348c..2b90c70 100755 --- a/bin/po.sh +++ b/bin/po.sh @@ -1,9 +1,9 @@ #!/bin/bash # shut down computer after checking running applications -read -p "Press enter to shutdown computer '$(hostname)'" +read -r -p "Press enter to shutdown computer '$(hostname)'" -PROGRAMS=("spotify" "firefox" "thunderbird" "ssh" "scp" "rsync" "pacman" "nemo" "vim" "gvim") +PROGRAMS=("firefox" "thunderbird" "ssh" "scp" "rsync" "pacman" "nemo" "vim" "gvim" "pacman" "vivaldi-bin") READY=0 @@ -18,11 +18,19 @@ while [ $READY -eq 0 ] ; do READY=0 done done + STATUS="$(dropbox-cli status)" + while [ "$STATUS" != "Up to date" -a "$STATUS" != "Connecting..." -a "$STATUS" != "Dropbox isn't running!" ] ; do + echo "Dropbox is still syncing!" + sleep 5 + READY=0 + STATUS="$(dropbox-cli status)" + done done -poweroff -if [ $? -ne 0 ] ; then +if poweroff; then + echo "Goodbye :)" +else echo "Higher privileges are required!" if type sudo > /dev/null ; then sudo poweroff diff --git a/bin/rename_images b/bin/rename_images index 20886a8..f024f7c 100755 --- a/bin/rename_images +++ b/bin/rename_images @@ -1,19 +1,38 @@ #!/bin/env python3 # vim: noexpandtab ts=4 ft=python : +""" +Rename all jpg images in the current folder. If there is a NEF image with the same same, +rename it as well. +""" + import os import re +import datetime import operator import PIL.Image import PIL.ExifTags def get_date(filename): - img = PIL.Image.open(filename) - d = re.match(r'(?P\d{4}):(?P\d{2}):(?P\d{2}) (?P\d{2}):(?P\d{2}):(?P\d{2})', img._getexif()[306]) - if d is None: + """ + Get date and time from image exif tag and return string with format %Y%m%d_%H%M%S + """ + try: + img = PIL.Image.open(filename) + e = img._getexif() + if 306 in e: + index = 306 + elif 36867 in e: + index = 36867 + elif 36838 in e: + index = 36868 + d = datetime.datetime.strptime(e[index], "%Y:%m:%d %H:%M:%S") + img.close() + return d.strftime("%Y%m%d_%H%M%S") + except Exception as e: + print(e) + exit(2) return None - img.close() - return "%04d%02d%02d_%02d%02d%02d" % (int(d["year"]), int(d["month"]), int(d["day"]), int(d["hour"]), int(d["minute"]), int(d["second"])) def print_new_filename(number, date, name, original_filename): ext = original_filename.split('.')[-1] @@ -37,10 +56,10 @@ if PIL.ExifTags.TAGS[306] != "DateTime": print("Warning: EXIF index for DateTime changed!") exit(2) -images = [[get_date(os.path.join(os.getcwd(), f)), f] for f in os.listdir(os.getcwd()) if os.path.isfile(os.path.join(os.getcwd(), f)) and re.search(r'\.jpg$', f, flags=re.IGNORECASE)] +images = [[get_date(os.path.join(os.getcwd(), f)), f] for f in os.listdir(os.getcwd()) if os.path.isfile(os.path.join(os.getcwd(), f)) and re.search(r'\.jpe?g$', f, flags=re.IGNORECASE)] images = sorted(images, key=operator.itemgetter(0, 1)) i = 1 for img in images: - rename_file_and_nef(i, img[0], "thomas", img[1]) + rename_file_and_nef(i, img[0], "mfg-who-am-i", img[1]) i += 1 diff --git a/bin/sort_images_into_folders b/bin/sort_images_into_folders index eba25a7..1bb9d56 100755 --- a/bin/sort_images_into_folders +++ b/bin/sort_images_into_folders @@ -27,6 +27,20 @@ def get_date(filename): return None return "%04d%02d%02d" % (int(matches["year"]), int(matches["month"]), int(matches["day"])) +def create_directory(directory): + """ + Try to create the directory return False when there’s already something there that’s not a + directory + """ + if os.path.exists(directory): + if not os.path.isdir(directory): + print("'%s' exists but is no directory!" % (directory)) + return False + else: + print("Creating directory '%s'" % (directory)) + os.mkdir(directory) + return True + def main(): """ Move files to a directory by date @@ -45,11 +59,15 @@ def main(): help="The destination directory (default = current)", dest="destination") parser.add_argument("--copy", "-c", action="store_true", dest="copy_files", \ help="Copy the files insted of moving them") + parser.add_argument("--existing", "-e", action="store", dest="existing_files", \ + choises=["ask", "skip", "overwrite"], default="ask", \ + help="What to do with existing files") args = parser.parse_args() # settings source_directory = args.source destination_directory = args.destination copy_files = args.copy_files + existing_files = args.existing_files # iterate through directory for filename in os.listdir(source_directory): if os.path.isfile(os.path.join(source_directory, filename)) and \ @@ -60,15 +78,21 @@ def main(): continue directory = os.path.join(destination_directory, date) # create directory if it not exists - if os.path.exists(directory): - if not os.path.isdir(directory): - print("'%s' exists but is no directory!" % (date)) - continue - else: - print("Creating directory '%s'" % (directory)) - os.mkdir(directory) + if not create_directory(directory): + continue # copy or move file - if copy_files: + write_file = True + if os.path.exists(os.path.join(destination_directory, date, filename)) and \ + existing_files != "overwrite": + write_file = False + if existing_files == "ask": + overwrite = input("File '%s' exists! Overwrite? [yn]: ") + while overwrite not in ["y", "n"]: + overwrite = input("File '%s' exists! Overwrite? [yn]: ") + write_file = overwrite == "y" + if not write_file: + print("Skipping file '%s'" % (filename)) + elif copy_files: print("Copy file '%s' to '%s'" % (filename, date)) shutil.copy2(os.path.join(source_directory, filename), \ os.path.join(destination_directory, date, filename)) diff --git a/i3/config b/i3/config index 5a9d778..b0b9516 100644 --- a/i3/config +++ b/i3/config @@ -146,6 +146,8 @@ assign [class="aurora"] → 2 assign [class="Opera"] → 2 assign [class="Midori"] → 2 assign [class="Chromium"] → 2 +assign [class="vivaldi-stable"] → 2 +assign [class="Vivaldi-stable"] → 2 assign [class="Thunderbird"] → 3 for_window [class="XTerm"] floating enable for_window [class="feh"] floating enable diff --git a/vim/plug.vim b/vim/plug.vim index 3b7d01b..85a30d2 100644 --- a/vim/plug.vim +++ b/vim/plug.vim @@ -42,6 +42,7 @@ Plug 'niklasl/vim-rdf' Plug 'nathanaelkane/vim-indent-guides' Plug 'chrisbra/csv.vim' Plug 'vim-scripts/icalendar.vim' +Plug 'cespare/vim-toml' " Files Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } diff --git a/xprofile b/xprofile index 7bf1355..0a04a87 100644 --- a/xprofile +++ b/xprofile @@ -11,5 +11,3 @@ fi # Environment variables # export GTK2_RC_FILES="$HOME/.gtkrc-2.0" - -xrandr --output DVI-0 --auto --left-of HDMI-0