了解です。以下は VLC の Lua 拡張 (プラグイン) で、再生中のファイルをゴミ箱に送る(もしくは削除する)処理を行うものです。重要な点から先に:
-
注意:VLC の Lua 拡張で「右クリックメニューそのもの」を直接変更することはできません(VLC のネイティブ右クリックコンテキストメニューを拡張する API は公開されていません)。代わりに「View(表示)メニュー → 拡張機能」として表示される 拡張 (extension) を作ります。拡張を開くと小さなダイアログが出て、そこで「Delete current file」ボタンを押すだけで削除できます。キーボードショートカットを割り当てたい場合は別途方法が必要ですが(ウィンドウマネージャのキー割当/xdotool 等でボタンを押す自動化など)、まずは拡張で確実に動くものを用意します。
1) Lua 拡張コード(コピペして使える)
ファイル名:~/.local/share/vlc/lua/extensions/delete_current.lua
作成して以下を丸ごと貼り付けてください。
-- delete_current.lua
-- VLC extension: delete (move to trash) the currently playing file
function descriptor()
return {
title = "Delete current file",
version = "1.0",
author = "assistant",
url = '',
shortdesc = "Move current file to trash / delete",
description = "Move the currently playing file to Trash (prefers gio or trash-put).",
capabilities = {}
}
end
local dlg = nil
local status_label = nil
function activate()
dlg = vlc.dialog("Delete current file")
dlg:add_label("この操作は再生中のファイルをゴミ箱へ移動します。", 1, 1, 1, 1)
dlg:add_button("Delete (Trash)", do_delete_trash, 1, 2, 1, 1)
dlg:add_button("Delete (rm)", do_delete_rm, 2, 2, 1, 1)
status_label = dlg:add_label("", 1, 3, 2, 1)
update_status()
end
function deactivate()
if dlg then
dlg:delete()
dlg = nil
end
end
function close()
deactivate()
end
-- helper to get current input's filesystem path from file:// URI
local function uri_to_path(uri)
if not uri then return nil end
-- accept file:///... or file:/... (normalize)
local m = string.match(uri, "^file:///(.*)") or string.match(uri, "^file:(.*)")
if not m then
-- maybe non-file (http) or other
return nil
end
-- percent-decode
local function pct_decode(s)
s = s:gsub("%%(%x%x)", function(h) return string.char(tonumber(h,16)) end)
return s
end
local path = "/" .. m -- ensure leading slash if necessary
path = pct_decode(path)
return path
end
local function current_path()
local item = vlc.input.item()
if not item then return nil end
local uri = item:uri()
return uri_to_path(uri)
end
local function update_status(msg)
local p = current_path()
local text = ""
if msg then
text = msg
elseif not p then
text = "No file playing."
else
text = "Current: " .. p
end
if status_label then status_label:set_text(text) end
end
-- try to move to trash using available commands
function do_delete_trash()
local p = current_path()
if not p then
update_status("再生ファイルを取得できません。")
return
end
-- attempt gio trash, then trash-put, then fallback to rm -f
local cmd1 = 'gio trash "' .. p .. '"'
local cmd2 = 'trash-put "' .. p .. '"'
local cmd3 = 'rm -f "' .. p .. '"'
update_status("Trying gio trash...")
local ok = os.execute(cmd1)
if ok then
update_status("Moved to trash (gio): " .. p)
return
end
update_status("gio failed, trying trash-put...")
ok = os.execute(cmd2)
if ok then
update_status("Moved to trash (trash-put): " .. p)
return
end
update_status("Both trash tools failed. Use Delete (rm) to force delete, or install gio/trash-cli.")
end
-- force delete
function do_delete_rm()
local p = current_path()
if not p then
update_status("再生ファイルを取得できません。")
return
end
-- warn the user
local w = vlc.dialogs and vlc.dialogs or nil
-- Stop playback first
pcall(function() vlc.playlist.stop() end)
local cmd = 'rm -f "' .. p .. '"'
local ok = os.execute(cmd)
if ok then
update_status("Deleted (rm): " .. p)
else
update_status("Failed to rm: " .. p)
end
end
2) 使い方(インストールと実行)
-
ファイルを作成:
mkdir -p ~/.local/share/vlc/lua/extensions
# テキストエディタで保存
nano ~/.local/share/vlc/lua/extensions/delete_current.lua
# (上のコードを貼り付けて保存)
-
必要な外部ツール(推奨)
-
gio(GNOME のgvfsに含まれるコマンド)またはtrash-cli(trash-put)のいずれかがあると安全にゴミ箱へ移動できます。無ければrmを呼びます(危険)。 -
NixOS なら
configuration.nixに例えば:
environment.systemPackages = with pkgs; [
gvfs # provides gio
trash-cli # provides trash-put
];
設定を反映して再起動または nixos-rebuild switch。
-
VLC を再起動してメニューを確認
VLC のメニュー →表示 (View)に「Delete current file」が現れます。選ぶとダイアログが出て、Delete (Trash)ボタンでごみ箱へ、Delete (rm)で強制削除(注意!)です。
3) 重要な注意点(必ず読んでください)
-
右クリック直接追加不可:VLC の通常のコンテキスト(右クリック)メニューにこの項目を差し込むことはできません。メニューは「表示 → 拡張機能」から呼び出す形になります。
-
安全第一:
Delete (Trash)が利用できるか確認してください。rmはファイル完全削除です。誤削除に注意してください。 -
パーミッション:再生ファイルが root や他ユーザー所有の場合、削除できないことがあります(権限不足)。
-
デコード:Lua 内で file:/// URI からパスへ変換する処理を入れていますが、特殊な URI(リモートプロトコルや特殊システム)では動かない場合があります。
これで作って試してみてください。動かなかったり、より「右クリックっぽく」使いたい(たとえばキーボードショートカットや自動でダイアログを開く仕組み)などの改善希望があれば、そのまま対応案(例:xdotool でショートカット割当、Vim-like hotkey を使う方法、ダイアログ自動化など)を提示します。どうしますか?