Skip to content

Commit 99f73cb

Browse files
committed
add edit
1 parent 057fa1a commit 99f73cb

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

mutate

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import readline
1919
import sys
2020
from shutil import get_terminal_size
2121

22-
from prompt_toolkit import PromptSession
22+
from prompt_toolkit import PromptSession, prompt
2323
from prompt_toolkit.completion import WordCompleter
2424
from prompt_toolkit.auto_suggest import AutoSuggest, Suggestion
2525
from prompt_toolkit.shortcuts import clear
@@ -47,11 +47,11 @@ dataExtr = {
4747
cmd_print = "print"
4848
cmd_tags = "tags"
4949
cmd_remove = "remove"
50-
cmd_rename = "rename"
50+
cmd_edit = "edit"
5151
cmd_write = "write"
5252
cmd_quit = "quit"
5353

54-
cmds = [cmd_print, cmd_tags, cmd_remove, cmd_rename, cmd_write, cmd_quit]
54+
cmds = [cmd_print, cmd_tags, cmd_remove, cmd_edit, cmd_write, cmd_quit]
5555
class CommandSuggest(AutoSuggest):
5656
def get_suggestion(this, buffer, document):
5757
if document.find_backwards(cmd_remove):
@@ -174,6 +174,19 @@ def remove(what, df):
174174
cols.append(token)
175175
df.drop(index=idxs, columns=cols, inplace=True)
176176

177+
def edit(df, idx, col):
178+
if idx == None:
179+
if col == f_filename:
180+
val = prompt("New template for 'filename': ")
181+
# TODO %01d for nums of total <10
182+
df[f_filename] = df.apply(lambda r: val.replace('%n', '%02d' % (r[f_num])).replace('%a', r[f_artist]).replace('%t', r[f_title]), axis=1)
183+
else:
184+
val = prompt("New values for '%s': " % (col), default=df[col].mode()[0])
185+
df[col] = val
186+
else:
187+
val = prompt("New value for '%s': " % (col), default=df.loc[idx, col])
188+
df.loc[idx, col] = val
189+
177190
fs = list(filter(isfile, listdir()))
178191
if not fs:
179192
print("Nothing interesting at", getcwd())
@@ -227,6 +240,15 @@ else:
227240
if cmd.startswith(cmd_remove):
228241
what = cmd.split(' ')[1:]
229242
remove(what, df)
243+
elif cmd.startswith(cmd_edit):
244+
idx = None
245+
col = None
246+
for i in cmd.split(' ')[1:]:
247+
if i.isdigit():
248+
idx = int(i)
249+
elif i in df.columns.drop('file'):
250+
col = i
251+
edit(df, idx, col)
230252
elif cmd == cmd_print:
231253
printData()
232254
elif cmd.startswith(cmd_tags):

0 commit comments

Comments
 (0)