Added sanitize function to sanitize filenames #307

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
2 participants

Added sanitize function to sanitize filenames (only letters, digits, dash, underscore and dots).

I frequently get files from others with capital letters, spaces, etc. This function cleans up the file names.

@marcobalk marcobalk Added sanitize function to sanitize filenames
(only letters, digits, dash, underscore and dots)
4dc3f42

@mathiasbynens mathiasbynens and 1 other commented on an outdated diff Dec 7, 2013

@@ -311,3 +311,14 @@ function np() {
function tre() {
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX
}
+
+# sanitize filename: lowercase, no other characters than letters, digits, dash, underscore and dot
+function sanitize() {
+ for file in *; do
+ file_clean=`echo $file | tr '[:upper:]' '[:lower:]' | tr -cd "[:alnum:]-_."`
@mathiasbynens

mathiasbynens Dec 7, 2013

Owner

Could you make this a local and also use $() syntax instead of the backticks, for consistency with the other code in this repository?

@marcobalk

marcobalk Dec 7, 2013

Good idea. Done!

On 07-12-13 15:01, Mathias Bynens wrote:

In .functions:

@@ -311,3 +311,14 @@ function np() {
function tre() {
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX
}
+
+# sanitize filename: lowercase, no other characters than letters, digits, dash, underscore and dot
+function sanitize() {

  • for file in *; do
  •   file_clean=`echo $file | tr '[:upper:]' '[:lower:]' | tr -cd "[:alnum:]-_."`
    

Could you make this a |local| and also use |$()| syntax instead of the
backticks, for consistency with the other code in the file?


Reply to this email directly or view it on GitHub
https://github.com/mathiasbynens/dotfiles/pull/307/files#r8181468.

@mathiasbynens mathiasbynens and 1 other commented on an outdated diff Dec 7, 2013

@@ -311,3 +311,14 @@ function np() {
function tre() {
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX
}
+
+# sanitize filename: lowercase, no other characters than letters, digits, dash, underscore and dot
+function sanitize() {
+ for file in *; do
@mathiasbynens

mathiasbynens Dec 7, 2013

Owner

file should be local too.

@marcobalk

marcobalk Dec 7, 2013

Ahh, right... Missed that one. :)

On 07-12-13 19:02, Mathias Bynens wrote:

In .functions:

@@ -311,3 +311,14 @@ function np() {
function tre() {
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX
}
+
+# sanitize filename: lowercase, no other characters than letters, digits, dash, underscore and dot
+function sanitize() {

  • for file in *; do

|file| should be local too.


Reply to this email directly or view it on GitHub
https://github.com/mathiasbynens/dotfiles/pull/307/files#r8182120.

Owner

mathiasbynens commented Jun 7, 2014

Thanks, but I don’t need this often enough to justify having it as part of my dotfiles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment