Skip to content

Commit d874fb7

Browse files
committed
release-ready
1 parent 22dcdfd commit d874fb7

File tree

7 files changed

+95
-31
lines changed

7 files changed

+95
-31
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ Debug
33
obj
44
*.exe
55
*.dll
6-
*.lcpkg
6+
*.lcp
77
share/scripts

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@
33

44
TUI file manager for [LeoConsole](https://github.com/BoettcherDasOriginal/LeoConsole)
55

6-
It is just a wrapper for [lf](https://github.com/gokcehan/lf).
6+
It is just a wrapper for [gokcehan/lf](https://github.com/gokcehan/lf).
7+
8+
## Installation
9+
10+
```
11+
apkg get file-manager
12+
```
713

build.sh

+19-15
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,26 @@ mkdir -vp "$CACHE_DIR" || exit 1
88
# build plugin dll
99
dotnet build --nologo || exit 1
1010

11-
# clone lf
12-
cd "$CACHE_DIR"
13-
if [ ! -d "./lf" ]; then
14-
git clone "https://github.com/gokcehan/lf.git"
15-
fi
11+
# download lf
12+
base_dl_url="https://github.com/gokcehan/lf/releases/latest/download"
13+
14+
get_lf_linux(){
15+
temp_file="$CACHE_DIR/lf.tar.gz"
16+
wget -nv -O "$temp_file" "$base_dl_url/lf-linux-amd64.tar.gz" || exit 1
17+
tar xzf "$temp_file" || exit 1
18+
cp -v "./lf" "$PROJECT_FOLDER/share/scripts/lf" || exit 1
19+
}
20+
21+
get_lf_windows(){
22+
temp_file="$CACHE_DIR/lf.zip"
23+
wget -nv -O "$temp_file" "$base_dl_url/lf-windows-amd64.zip" || exit 1
24+
unzip "$temp_file" || exit 1
25+
cp -v "./lf.exe" "$PROJECT_FOLDER/share/scripts/lf.exe" || exit 1
26+
}
1627

17-
# build lf
18-
cd "./lf"
1928
case "$APKG_BUILDER_OS" in
20-
lnx64) export GOOS="linux"; export GOARCH="amd64"; OUT="lf" ;;
21-
win64) export GOOS="windows"; export GOARCH="amd64"; OUT="lf.exe" ;;
22-
*) export GOOS="linux"; export GOARCH="amd64"; OUT="lf" ;;
29+
lnx64) get_lf_linux ;;
30+
win64) get_lf_windows ;;
31+
*) get_lf_linux ;;
2332
esac
24-
go build . || exit 1
25-
cd "$PROJECT_FOLDER"
26-
27-
# copy lf binary
28-
cp -v "$CACHE_DIR/lf/$OUT" "$PROJECT_FOLDER/share/scripts/$OUT"
2933

command.cs

+42-12
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,61 @@
1+
using ILeoConsole.Core;
2+
using ILeoConsole.Plugin;
3+
using ILeoConsole;
14
using System.Diagnostics;
25
using System.IO;
3-
using ILeoConsole;
4-
using ILeoConsole.Plugin;
5-
using ILeoConsole.Core;
6+
using System.Runtime.InteropServices;
67

78
namespace LeoConsole_FileManager
89
{
910
public class FileManager : ICommand
1011
{
1112
public string Name { get { return "fm"; } }
1213
public string Description { get { return "TUI file manager"; } }
13-
public Action CommandFunktion { get { return () => Command(); } }
14-
private string[] _InputProperties;
15-
public string[] InputProperties { get { return _InputProperties; } set { _InputProperties = value; } }
14+
public Action CommandFunction { get { return () => Command(); } }
15+
public Action HelpFunction { get { return () => Console.WriteLine("not available"); } }
16+
private string[] _Arguments;
17+
public string[] Arguments { get { return _Arguments; } set { _Arguments = value; } }
1618
public IData data = new ConsoleData();
1719

1820
public void Command()
1921
{
20-
RunProcess(
21-
Path.Join(data.SavePath, "share", "scripts", "lf"),
22-
"",
23-
data.SavePath
24-
);
22+
RunProcess(GetLfPath(), $"-config {data.SavePath}/share/file-manager/lfrc", data.SavePath);
23+
}
24+
25+
// get lf binary path
26+
private string GetLfPath()
27+
{
28+
string basePath = Path.Join(data.SavePath, "share", "scripts");
29+
if (GetRunningOS() == "lnx64") {
30+
string path = Path.Join(basePath, "lf");
31+
if (File.Exists(path)) {
32+
return path;
33+
}
34+
throw new Exception("builder binary not found");
35+
}
36+
if (GetRunningOS() == "win64") {
37+
string path = Path.Join(basePath, "lf.exe");
38+
if (File.Exists(path)) {
39+
return path;
40+
}
41+
throw new Exception("builder binary not found");
42+
}
43+
throw new Exception("unknown OS");
44+
}
45+
46+
// get OS
47+
private string GetRunningOS() {
48+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
49+
return "win64";
50+
}
51+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
52+
return "lnx64";
53+
}
54+
return "other";
2555
}
2656

2757
// run a process with parameters and wait for it to finish
28-
public void RunProcess(string name, string args, string pwd)
58+
private void RunProcess(string name, string args, string pwd)
2959
{
3060
try
3161
{

manifest.apkg.json renamed to manifest.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
2-
"manifestVersion": 2.1,
2+
"manifestVersion": 3.0,
33
"packageName": "file-manager",
44
"packageVersion": "0.0.1",
5+
"depends": [],
6+
"compatibleVersions": ["2.1.0"],
57
"build": {
68
"command": "sh",
79
"args": ["./build.sh"],

plugin.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ public class FileManagerPlugin : IPlugin
3232
public void PluginInit()
3333
{
3434
_data = new ConsoleData();
35-
3635
_Commands = new List<ICommand>();
36+
}
37+
38+
public void RegisterCommands()
39+
{
3740
_Commands.Add(new FileManager());
3841
}
3942

share/file-manager/lfrc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
set drawbox # draw borders
3+
set info size # show file sizes
4+
set incsearch # search as you are typing
5+
set incfilter # filter as you are typingr
6+
set preview # preview files on the right side
7+
8+
# prompt at the top
9+
set promptfmt "\033[36mLeoConsole File Manager\033[0m - Powered by \033[33mLF\033[0m (github.com/gokcehan/lf)"
10+
# panes ratio
11+
set ratios 1:2:3
12+
13+
# move in upper directories
14+
map J :push hjl
15+
map K :push hkl
16+
17+
# Vim-style ":q" exit
18+
cmd q :quit
19+

0 commit comments

Comments
 (0)