rename dupes
This commit is contained in:
@@ -13,11 +13,12 @@ function clearsafe() {
|
|||||||
}
|
}
|
||||||
SAFELOC=~/.cache/rm-safe
|
SAFELOC=~/.cache/rm-safe
|
||||||
FOLDERS=()
|
FOLDERS=()
|
||||||
|
QUIET="-q"
|
||||||
[[ -z "$1" ]] && helpexit
|
[[ -z "$1" ]] && helpexit
|
||||||
for ((i=1; i<=${#@}; i++)) {
|
for ((i=1; i<=${#@}; i++)) {
|
||||||
[[ "${!i}" = "-h" ]] && helpexit
|
[[ "${!i}" = "-h" ]] && helpexit
|
||||||
[[ "${!i}" = "--help" ]] && helpexit
|
[[ "${!i}" = "--help" ]] && helpexit
|
||||||
[[ "${!i}" = "-v" ]] && { VERBOSE=1; continue; }
|
[[ "${!i}" = "-v" ]] && { VERBOSE=1; QUIET=""; continue; }
|
||||||
[[ "${!i}" = "--clear" ]] && { clearsafe; continue; }
|
[[ "${!i}" = "--clear" ]] && { clearsafe; continue; }
|
||||||
[[ "${!i}" = "-"* ]] && helpexit
|
[[ "${!i}" = "-"* ]] && helpexit
|
||||||
FOLDERS+=( "${!i}" )
|
FOLDERS+=( "${!i}" )
|
||||||
@@ -28,8 +29,8 @@ for d in "${FOLDERS[@]}"; do
|
|||||||
if [[ ! -e "$d" ]]; then continue; fi
|
if [[ ! -e "$d" ]]; then continue; fi
|
||||||
path=$( readlink -f "$d" )
|
path=$( readlink -f "$d" )
|
||||||
dir=$( dirname "$path" )
|
dir=$( dirname "$path" )
|
||||||
if [[ "$VERBOSE" -eq 1 ]]; then echo "$path"; fi
|
if [[ "$VERBOSE" -eq 1 ]]; then echo "$SAFELOC/$now/$path"; fi
|
||||||
if [[ -e "$SAFELOC/$now/$path" ]]; then file-version -q "$SAFELOC/$now/$path"; fi
|
if [[ -e "$SAFELOC/$now/$path" ]]; then file-version $QUIET "$SAFELOC/$now/$path"; fi
|
||||||
mkdir -p "$SAFELOC/$now/$dir"
|
mkdir -p "$SAFELOC/$now/$dir"
|
||||||
mv "$d" "$SAFELOC/$now/$dir"
|
mv "$d" "$SAFELOC/$now/$dir"
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
'''Markslider: a slideshow engine based on markdown.'''
|
'''Markslider: a slideshow engine based on markdown.'''
|
||||||
|
|
||||||
__author__ = "Ville Rantanen <ville.q.rantanen@gmail.com>"
|
__author__ = "Ville Rantanen <ville.q.rantanen@gmail.com>"
|
||||||
__version__ = "1.1"
|
__version__ = "1.2"
|
||||||
|
|
||||||
import sys,os,argparse,re,datetime
|
import sys,os,argparse,re,datetime
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
@@ -49,7 +49,7 @@ class EndProgram( Exception ):
|
|||||||
|
|
||||||
class slide_reader:
|
class slide_reader:
|
||||||
""" Class for reading files. """
|
""" Class for reading files. """
|
||||||
def __init__(self,files,opts):
|
def __init__(self, files, opts):
|
||||||
self.filename = files[0]
|
self.filename = files[0]
|
||||||
self.files = files
|
self.files = files
|
||||||
self.reader = None
|
self.reader = None
|
||||||
@@ -105,6 +105,7 @@ class slide_reader:
|
|||||||
self.file_start_page.append(len(self.data))
|
self.file_start_page.append(len(self.data))
|
||||||
if len(self.data)==0:
|
if len(self.data)==0:
|
||||||
raise ValueError("File does not have a # header")
|
raise ValueError("File does not have a # header")
|
||||||
|
self.rename_duplicates()
|
||||||
self.toc()
|
self.toc()
|
||||||
self.pages=len(self.data)
|
self.pages=len(self.data)
|
||||||
self.inc_page_no(0)
|
self.inc_page_no(0)
|
||||||
@@ -257,6 +258,23 @@ class slide_reader:
|
|||||||
return return_value
|
return return_value
|
||||||
# return [s]
|
# return [s]
|
||||||
|
|
||||||
|
def rename_duplicates(self):
|
||||||
|
|
||||||
|
if not opts.rename_title:
|
||||||
|
return
|
||||||
|
|
||||||
|
titles = {}
|
||||||
|
page_nos = []
|
||||||
|
for page in self.data:
|
||||||
|
if not page[0] in titles:
|
||||||
|
titles[page[0]] = 0
|
||||||
|
titles[page[0]] += 1
|
||||||
|
page_nos.append(titles[page[0]])
|
||||||
|
|
||||||
|
for page, page_no in zip(self.data, page_nos):
|
||||||
|
if titles[page[0]] > 1:
|
||||||
|
page[0] += " [%d/%d]"%( page_no, titles[page[0]] )
|
||||||
|
|
||||||
|
|
||||||
def get_interactive_help_text():
|
def get_interactive_help_text():
|
||||||
return ''' left/right,page up/down,home,end
|
return ''' left/right,page up/down,home,end
|
||||||
@@ -308,6 +326,8 @@ Keyboard shortcuts:
|
|||||||
help="Disable color by markdown structure.")
|
help="Disable color by markdown structure.")
|
||||||
content.add_argument("--no-color","-n",action="store_false",dest="color",default=True,
|
content.add_argument("--no-color","-n",action="store_false",dest="color",default=True,
|
||||||
help="Disable color.")
|
help="Disable color.")
|
||||||
|
content.add_argument("--no-rename","--nr",action="store_false",dest="rename_title", default=True,
|
||||||
|
help="Disable automatic renaming of duplicate titles.")
|
||||||
|
|
||||||
execution.add_argument("-e",action="store_true",dest="execute",default=False,
|
execution.add_argument("-e",action="store_true",dest="execute",default=False,
|
||||||
help="Execute commands in `! or `> tags at show time with Enter key. WARNING: Potentially very dangerous to run others' slides with this switch!")
|
help="Execute commands in `! or `> tags at show time with Enter key. WARNING: Potentially very dangerous to run others' slides with this switch!")
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user