Skip to content

Commit ba512ea

Browse files
committed
Support %DIR% variable; add Edit Global Setting MenuItem
1 parent a34e665 commit ba512ea

9 files changed

Lines changed: 47 additions & 40 deletions

File tree

ShellCommand/DataModel/DefaultSetting.cs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,5 @@ public static DirectoryCommand[] GetDirectoryCommand()
1414
new DirectoryCommand(){ Name = "Custom Command", Command = "cmd" },
1515
};
1616
}
17-
18-
public static GlobalConfig GetGlobal()
19-
{
20-
return new GlobalConfig()
21-
{
22-
GlobalCommands = new List<DirectoryCommand>()
23-
{
24-
new DirectoryCommand()
25-
{
26-
Command = "git pull",
27-
Match = ".git",
28-
},
29-
new DirectoryCommand()
30-
{
31-
Command = "git submodule update --init --recursive",
32-
Match = ".gitmodules",
33-
},
34-
new DirectoryCommand()
35-
{
36-
Name = "Open Command Window Here",
37-
Command = "cmd",
38-
},
39-
},
40-
Functions = new BuildinFunctions
41-
{
42-
CopyPath = true,
43-
}
44-
};
45-
}
4617
}
4718
}

ShellCommand/DataModel/DirectoryCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public class DirectoryCommand
1818

1919
public void Execute(string workingDir)
2020
{
21-
var (com, arg) = Cmd.SplitCommandArg(Command);
21+
var repcommand = Command.Replace(Env.VAR_DIR, workingDir.Replace("\\", "/"));
22+
var (com, arg) = Cmd.SplitCommandArg(repcommand);
2223
ProcessInfoChain ProcessInfoChain = ProcessInfoChain.New(com, arg);
2324
if (RunAsAdmin)
2425
{

ShellCommand/Env.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ public static class Env
1111
public const string AppName = "ShellCommand";
1212
public const string CommandFileName = ".shellcommand.yaml";
1313
public const string GlobalSettingFileName= "global.shellcommand.yaml";
14+
public const string GlobalTemplateSettingFileName = "global.template.shellcommand.yaml";
1415

1516
public const string CreateFolderSpecificFileText = "Create .shellcommand.yaml";
17+
public const string OpenGlobalSettingFileText = "Edit Global Setting";
1618
public const string OpenAppText = "Setting";
1719

1820
public const string ConfigTitle = "# ShellCommand: https://github.com/XUJINKAI/ShellCommand \r\n\r\n";
1921

22+
public const string VAR_DIR = "%DIR%";
2023

2124
public static string GetAppFolder()
2225
{

ShellCommand/MainWindow.xaml.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ private void Uninstall(object sender, RoutedEventArgs e)
7777

7878
private void AdminInstall()
7979
{
80-
var configpath = System.IO.Path.Combine(XJK.ENV.BaseDirectory, Env.GlobalSettingFileName);
81-
if (!File.Exists(configpath))
80+
var globalfile = System.IO.Path.Combine(XJK.ENV.BaseDirectory, Env.GlobalSettingFileName);
81+
if (!File.Exists(globalfile))
8282
{
83-
var setting = DataModel.DefaultSetting.GetGlobal();
84-
Util.Yaml.SaveYaml(configpath, setting);
83+
var templatefile = System.IO.Path.Combine(XJK.ENV.BaseDirectory, Env.GlobalTemplateSettingFileName);
84+
if (File.Exists(templatefile))
85+
File.Copy(templatefile, globalfile);
8586
}
8687
Util.Reg.SetExePath(XJK.ENV.EntryLocation);
8788
Util.Reg.SetLogPath();

ShellCommand/MenuDefinition/BuildinMenuItems.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ public static ToolStripMenuItem InitDirectoryFile(string path)
3434
return item;
3535
}
3636

37+
public static ToolStripMenuItem OpenGlobalSetting()
38+
{
39+
var item = new ToolStripMenuItem(Env.OpenGlobalSettingFileText);
40+
item.Click += (sender, args) =>
41+
{
42+
var path = Path.Combine(Env.GetAppFolder(), Env.GlobalSettingFileName);
43+
Cmd.RunAsInvoker(path, "");
44+
};
45+
return item;
46+
}
47+
3748
public static ToolStripMenuItem OpenApp()
3849
{
3950
var path = Util.Reg.GetExePath();

ShellCommand/MenuDefinition/DirectoryBackgroundContextMenu.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected override ContextMenuStrip CreateMenu()
3939
container.DropDownItems.Add(new ToolStripSeparator());
4040
}
4141

42-
var globalSettingPath = Path.Combine(Util.Reg.GetAppFolderPath(), Env.GlobalSettingFileName);
42+
var globalSettingPath = Path.Combine(Env.GetAppFolder(), Env.GlobalSettingFileName);
4343
if (File.Exists(globalSettingPath))
4444
{
4545
var globalItems = CommandFileParser.ParseGlobalCommand(globalSettingPath, FolderPath);
@@ -54,6 +54,8 @@ protected override ContextMenuStrip CreateMenu()
5454
{
5555
container.DropDownItems.Add(BuildinMenuItems.InitDirectoryFile(CommandFilePath));
5656
}
57+
58+
container.DropDownItems.Add(BuildinMenuItems.OpenGlobalSetting());
5759
container.DropDownItems.Add(BuildinMenuItems.OpenApp());
5860

5961
menu.Items.Add(container);

ShellCommand/ShellCommand.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@
178178
<None Include=".shellcommand.yaml">
179179
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
180180
</None>
181+
<None Include="global.template.shellcommand.yaml">
182+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
183+
</None>
181184
</ItemGroup>
182185
<ItemGroup>
183186
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">

ShellCommand/Util/Reg.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,5 @@ public static string GetExePath()
4242
return key.GetValue(ExePath) as string;
4343
}
4444
}
45-
46-
public static string GetAppFolderPath()
47-
{
48-
return Path.GetDirectoryName(GetExePath());
49-
}
5045
}
5146
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# ShellCommand: https://github.com/XUJINKAI/ShellCommand
2+
3+
GlobalCommands:
4+
- Name: Open SourceTree Here
5+
Command: cmd /c start %LocalAppData%\SourceTree\SourceTree.exe -f "%DIR%"
6+
Match: .git
7+
8+
- Command: git pull
9+
Match: .git
10+
- Command: git submodule update --init --recursive
11+
Match: .gitmodules
12+
13+
- Name: Open Command Window Here
14+
Command: cmd
15+
- Name: Open Command Window Here (Administrator)
16+
Command: cmd /K "cd /d ""%DIR%"""
17+
RunAsAdmin: true
18+
19+
Functions:
20+
CopyPath: true

0 commit comments

Comments
 (0)