;; This is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;; These are commonly used bash utils, to be used when shs has been started..
(defun shsu-mounted-p (string)
"Return nil if string does not appear in mount output, else return
the matched lines. "
(shsh (format "%s %s" "mount | grep"
(shell-quote-argument (format "%s" string))))))
(defun shsu-as-root (string)
"shsh on string. If not root, append a sudo before the string.
Run a shell command indicated by string, but with sudo appended if
((string= (shsu-whoami) "root")
(shsm "Your sudo should  either be password-expiry free")
(shsm " Else, make sure to reauthenticate before running this script,")
(shsm ".. for example, by typing sudo echo hi")
(shsm ".... else this script will fail")
(shsh (format "%s %s" "sudo" string)))))
(defun shsu-directory-files-dirs-files (dir)
"Removes . and .. List dirs first"
(defun shsu-sort-predicate-dirs-files (a b)
"Dirs first, then symlinks to dirs, then files, then symlinks to files"
(let ((ascore (shsu-sort-dirs-files-score a))
(bscore (shsu-sort-dirs-files-score b)))
((< ascore bscore)
((= ascore bscore) (string-lessp a b))
(defun shsu-funcall-recursive (f dir &optional predf0 predr0 predf2 predr2)
"Apply function f to each non-directory in the root of the supplied directory.
More specifically, do so only when predf is satisfied. By default,
predf is true only when the file is a regular file, which is not a
Predrecurse (predr0 and predr2) tells when to descend. By default,
this is true only if the subdir is a regular directory, which is not
a symlink. Both predr0 and predr2 must be satisfied.
predf0 and predr0 are meant to be specified by you for
situational-specific stuff in general. Their default values is
basically absent. Left blank for you. If you want to just deal with
every file, just supply us nil for these.... For example, they could
be functions that check to see if the file already has a gz suffix.
If you are in the mood to overwrite our descending criteria, then use
predf2 and predr2, Predf2 and predr2 are ADDITIONAL predicates to be
satisfied. These DO have default values which check for symlinks,
etc. . Use them if you DO want alter the default predicates, which are
predf0 and predr0.
(defun shsu-gz-recursive (dir)
"There will be ignored errors, for example, when there are hard
(shsm "Gzipping %s..." arg)
(shs-ignore-errors-flag (shsh (concat "/bin/gzip " arg)))
(shsm "Gzipping %s...done\n" arg))
(let ((e (file-name-extension a)))
(not (member e '("gz" "GZ" "txt")))))))
(defun shsu-sanitize-filename (file)
"Remove all stupid MSDOS spaces from filenames in this file.
You typically receive such files from windoze users.
Replace spaces by dashes"
(let* ((fname (file-name-nondirectory file))
(replacep (shs-ignore-errors-flag (string-match " " fname)))
(and replacep (shs-ignore-errors-flag (file-name-directory file)))))
(and replacep (replace-regexp-in-string " " "-" fname))))
(and replacep (shs-expand-file-name fname2
(and replacep (concat "Move " (progn file)
" to " (progn file2)))))
(rename-file file file2))))
(defun shsu-sanitize-filename-recursive (file)
"See shsu-sanitize-filename. Do this recursively. "