| [bookmarks](bookmarks) | Use named bookmarks managed with symlinks | sh | fzf |
| [boom](boom) | Play random music from dir | sh | [moc](http://moc.daper.net/) |
| [bulknew](bulknew) | Create multiple files/dirs at once | bash | sed, xargs, mktemp |
+| [cleanfilename](cleanfilename) | Clean filename to be more shell-friendly | sh | sed |
| [dups](dups) | List non-empty duplicate files in current dir | bash | find, md5sum,<br>sort uniq xargs |
| [chksum](chksum) | Create and verify checksums | sh | md5sum,<br>sha256sum |
| [diffs](diffs) | Diff for selection (limited to 2 for directories) | sh | vimdiff, mktemp |
--- /dev/null
+#!/usr/bin/env sh
+
+# Description: Clean filename (either hovered or selections)
+# to be more shell-friendly.
+# This script replaces any non A-Za-z0-9._- char
+# with underscore (_).
+#
+# Although the name is 'cleanfilename', but it should work
+# on directories too.
+#
+# Dependencies: sed
+#
+# Shell: POSIX compliant
+# Author: Benawi Adha
+
+prompt=true
+sel=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
+IFS='
+'
+
+cleanup() {
+ printf "%s" "$1" | sed -e 's/[^A-Za-z0-9._-]/_/g'
+}
+
+if [ -f "$sel" ]; then
+ targets=$(sed -e "s/\\x0/\\n/g;\$a\\" "$sel" | \
+ while read -r i; do
+ basename "$i";
+ done)
+else
+ targets=$1
+fi
+
+for i in $targets; do
+ printf "%s --> %s\n" "$i" "$(cleanup "$i")";
+done
+
+if $prompt; then
+ echo
+ printf "Proceed [Yn]? "
+ read -r input
+ case "$input" in
+ y|Y|'')
+ ;;
+ *)
+ echo "Canceled"
+ exit
+ ;;
+ esac
+fi
+
+for i in $targets; do
+ if [ "$i" != "$(cleanup "$i")" ]; then
+ mv "$i" "$(cleanup "$i")";
+ fi
+done