mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-13 13:44:28 +01:00
Compare commits
3 commits
e2b160d7c9
...
e5caf969d4
| Author | SHA1 | Date | |
|---|---|---|---|
| e5caf969d4 | |||
| 9987f1759c | |||
| 0e8835ca30 |
2 changed files with 137 additions and 3 deletions
61
bin/mark
61
bin/mark
|
|
@ -33,6 +33,17 @@ MARK_PREFIX=""
|
|||
done
|
||||
}
|
||||
|
||||
## file:: <file> <marks...>
|
||||
## Marks **files** with specific **mark**.
|
||||
## This creates symlinks for files in **mark** folder.
|
||||
@command file file {
|
||||
mark_root=$(mark.dir "$pwd")
|
||||
while [ "$#" -gt 0 ]; do
|
||||
mark="$1"; shift;
|
||||
mark.mark "$mark_root" "$file" "$MARK_PREFIX$mark"
|
||||
done
|
||||
}
|
||||
|
||||
## multiple:: <mark> <files...>
|
||||
## Marks **files** with specific **mark**.
|
||||
## This creates symlinks for files in **mark** folder.
|
||||
|
|
@ -89,7 +100,9 @@ MARK_PREFIX=""
|
|||
@command visual {
|
||||
nux.require feh
|
||||
marks=${MARK_TAGS:-person woman man selfie}
|
||||
mark_root=$(nux.fs.path.relative.pwd $(mark.dir $pwd/))
|
||||
mark_root="$(nux.fs.path.relative.pwd $(mark.dir "$pwd"))"
|
||||
#mark_root=$(mark.dir $pwd)
|
||||
nux.log debug "Mark Root:" $mark_root
|
||||
actions="";
|
||||
for mark in $marks; do
|
||||
((i++))
|
||||
|
|
@ -113,6 +126,43 @@ MARK_PREFIX=""
|
|||
--draw-tinted "$@"
|
||||
}
|
||||
|
||||
## unmarked:: mark [file+]
|
||||
## List files, which are not marked by particular mark
|
||||
## Note that this assumes current filename is same
|
||||
## TODO: Add support for different filenames in future
|
||||
##
|
||||
@command unmarked mark {
|
||||
mark_root=$(mark.dir $pwd)
|
||||
nux.log debug $(mark.dir $pwd) $mark_root;
|
||||
for path in "$@"; do
|
||||
nux.log debug "Checking file $path";
|
||||
name=${path##*/};
|
||||
marks="$(mark.marks-for-path "$mark_root" "$mark" "$path")"
|
||||
nux.log debug "$path has '$marks'";
|
||||
if [ -z "$marks" ]; then
|
||||
echo $path;
|
||||
fi
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
## unmarked:: mark [file+]
|
||||
## List files, which are not marked by particular mark
|
||||
## Note that this assumes current filename is same
|
||||
## TODO: Add support for different filenames in future
|
||||
##
|
||||
@command list {
|
||||
mark_root=$(mark.dir $pwd)
|
||||
nux.log debug $(mark.dir $pwd) $mark_root;
|
||||
for path in "$@"; do
|
||||
nux.log debug "Checking file $path";
|
||||
name=${path##*/};
|
||||
marks="$(mark.marks-for-path "$mark_root" "$mark" "$path")"
|
||||
for m in ${marks}; do
|
||||
fs:info "$path" "$m"
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
@namespace mark. {
|
||||
function :dir item {
|
||||
|
|
@ -135,4 +185,13 @@ MARK_PREFIX=""
|
|||
fs:symlink "$item" "$root/$mark" "$name"
|
||||
}
|
||||
|
||||
function :marks-for-path root mark path {
|
||||
name=${path##*/};
|
||||
find "$root/$mark" -iname "$name" 2> /dev/null | while read mark; do
|
||||
m="${mark#$root/}"
|
||||
m="${m%/*}";
|
||||
echo "$m";
|
||||
done
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
79
bin/medie
79
bin/medie
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
nux.use nux/fs
|
||||
|
||||
@prefix fs nux.fs.
|
||||
@prefix check nux.check.
|
||||
|
||||
|
||||
type ffmpeg > /dev/null 2>&1 && FFMPEG_OR_LIBAV=ffmpeg
|
||||
type avconv > /dev/null 2>&1 && FFMPEG_OR_LIBAV=avconv
|
||||
type gm > /dev/null 2>&1 && NUX_MAGICK=gm
|
||||
|
|
@ -55,6 +59,16 @@ nux.log debug "FFMPEG: $FFMPEG_OR_LIBAV Magick: $NUX_MAGICK"
|
|||
nuxr.run "$task" "$@"
|
||||
}
|
||||
|
||||
@command inplace task {
|
||||
NUX_INPLACE=true
|
||||
nuxr.run "$task" "$@"
|
||||
}
|
||||
|
||||
@command target-dir dir task {
|
||||
NUX_TARGET_DIR="$dir"
|
||||
nuxr.run "$task" "$@"
|
||||
}
|
||||
|
||||
## downscale:: <target> <size> <image...>
|
||||
## Creates downscaled copy of image in *target* directory.
|
||||
## Image is downsampled to fit in *size*. Smaller images are not upscaled.
|
||||
|
|
@ -72,9 +86,9 @@ nux.log debug "FFMPEG: $FFMPEG_OR_LIBAV Magick: $NUX_MAGICK"
|
|||
target_file="${target_dir}/$name";
|
||||
fi
|
||||
if $SKIP_CHECK "$target_file" ; then
|
||||
echo "Image: $i/$count Skipping"
|
||||
nux.log debug "$target_file" "($i/$count) Skipping"
|
||||
else
|
||||
echo "Image: $i/$count Downsampling $image -> '$target_file'"
|
||||
fs:info "$target_file" "($i/$count) Downsampling from $image"
|
||||
$NUX_MAGICK convert "$image" \
|
||||
-filter Lanczos -sampling-factor 1x1 \
|
||||
-resize "${SIZE}x${SIZE}>" \
|
||||
|
|
@ -100,6 +114,32 @@ nux.log debug "FFMPEG: $FFMPEG_OR_LIBAV Magick: $NUX_MAGICK"
|
|||
done
|
||||
}
|
||||
|
||||
## datetime-name:: <image...>
|
||||
## Normalizes name to format `yyyymmdd_hhmmss.suffix`
|
||||
###
|
||||
### Useful for:
|
||||
### - generating RGBD Images for *holograms* - *left is color* space, *right is depth*
|
||||
### - joining Instagram photos in slideshow, where photo is splitted in middle
|
||||
@command datetime-name {
|
||||
for file in "$@"; do
|
||||
date=$($NUX_MAGICK identify -format "%[EXIF:DateTimeOriginal]" "$file" 2> /dev/null)
|
||||
nux.log debug $file date is "'$date'"
|
||||
if [ "(" -n "$date" ")" -a "(" "$date" != "unknown" ")" ]; then
|
||||
target_dir=$(dirname "$file");
|
||||
target_file=${date//:/};
|
||||
target_file=${target_file/ /_};
|
||||
target_suffix=${file##*.}
|
||||
target_suffix=${target_suffix,,}
|
||||
target_full="$target_dir/$target_file.$target_suffix";
|
||||
fs:info "$file" Moving to: $target_full
|
||||
fs:stage mv "$file" "$target_full"
|
||||
else
|
||||
fs:warning "$file" Can not identify date from EXIF
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
## side-by-side:: <left> <right> <output>
|
||||
## Joins two images horizontal (assuming they have same size).
|
||||
###
|
||||
|
|
@ -125,6 +165,17 @@ nux.log debug "FFMPEG: $FFMPEG_OR_LIBAV Magick: $NUX_MAGICK"
|
|||
$NUX_MAGICK convert "$image" -gravity south -chop 0%x50% "$basename.2.$suffix"
|
||||
}
|
||||
|
||||
|
||||
@command crop-to-aspect aspect gravity {
|
||||
aspect_suffix=${aspect/:/_}
|
||||
for image in "$@"; do
|
||||
target="$(target.from "$image" "$aspect_suffix")";
|
||||
#nux.fs.info "$image": Target image: "$target"
|
||||
convert "$image" -gravity "$gravity" -crop "$aspect" "$target"
|
||||
nux.fs.info "$target" "Image cropped to aspect ratio: $aspect"
|
||||
done;
|
||||
}
|
||||
|
||||
## list-smaller:: <size> <image...>
|
||||
## Lists images smaller than **size**.
|
||||
@command list-smaller size {
|
||||
|
|
@ -207,6 +258,8 @@ nux.log debug "FFMPEG: $FFMPEG_OR_LIBAV Magick: $NUX_MAGICK"
|
|||
--draw-tinted "$@"
|
||||
}
|
||||
|
||||
|
||||
|
||||
function img.largest {
|
||||
## FIXME: Identify largest image
|
||||
nux.fs.path.relative.pwd "$1";
|
||||
|
|
@ -224,6 +277,28 @@ function no_skip {
|
|||
return 1;
|
||||
}
|
||||
|
||||
function target.from image qualifier extension {
|
||||
if [ -n "$NUX_INPLACE" ]; then
|
||||
nux.log trace "Inplace edit: $image"
|
||||
echo "$image"
|
||||
else
|
||||
orig_extension="${image##*.}"
|
||||
basename="${image%.*}"
|
||||
#if [-n "$NUX_TARGET_DIR" ];
|
||||
#target_dir="$NUX_TARGET_DIR"
|
||||
|
||||
target="$basename"
|
||||
if [ -n "$qualifier" ]; then
|
||||
target="$target.$qualifier"
|
||||
fi
|
||||
if [ -n "$extension" ]; then
|
||||
target="$target.$extension"
|
||||
else
|
||||
target="$target.$orig_extension"
|
||||
fi
|
||||
echo $target
|
||||
fi
|
||||
}
|
||||
|
||||
@command mass-crop label target {
|
||||
for img in "$@"; do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue