Skip to content

Commit

Permalink
Support %DIR% variable; add Edit Global Setting MenuItem
Browse files Browse the repository at this point in the history
  • Loading branch information
XUJINKAI committed Oct 9, 2019
1 parent a34e665 commit ba512ea
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 40 deletions.
29 changes: 0 additions & 29 deletions ShellCommand/DataModel/DefaultSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,5 @@ public static DirectoryCommand[] GetDirectoryCommand()
new DirectoryCommand(){ Name = "Custom Command", Command = "cmd" },
};
}

public static GlobalConfig GetGlobal()
{
return new GlobalConfig()
{
GlobalCommands = new List<DirectoryCommand>()
{
new DirectoryCommand()
{
Command = "git pull",
Match = ".git",
},
new DirectoryCommand()
{
Command = "git submodule update --init --recursive",
Match = ".gitmodules",
},
new DirectoryCommand()
{
Name = "Open Command Window Here",
Command = "cmd",
},
},
Functions = new BuildinFunctions
{
CopyPath = true,
}
};
}
}
}
3 changes: 2 additions & 1 deletion ShellCommand/DataModel/DirectoryCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class DirectoryCommand

public void Execute(string workingDir)
{
var (com, arg) = Cmd.SplitCommandArg(Command);
var repcommand = Command.Replace(Env.VAR_DIR, workingDir.Replace("\\", "/"));
var (com, arg) = Cmd.SplitCommandArg(repcommand);
ProcessInfoChain ProcessInfoChain = ProcessInfoChain.New(com, arg);
if (RunAsAdmin)
{
Expand Down
3 changes: 3 additions & 0 deletions ShellCommand/Env.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ public static class Env
public const string AppName = "ShellCommand";
public const string CommandFileName = ".shellcommand.yaml";
public const string GlobalSettingFileName= "global.shellcommand.yaml";
public const string GlobalTemplateSettingFileName = "global.template.shellcommand.yaml";

public const string CreateFolderSpecificFileText = "Create .shellcommand.yaml";
public const string OpenGlobalSettingFileText = "Edit Global Setting";
public const string OpenAppText = "Setting";

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

public const string VAR_DIR = "%DIR%";

public static string GetAppFolder()
{
Expand Down
9 changes: 5 additions & 4 deletions ShellCommand/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ private void Uninstall(object sender, RoutedEventArgs e)

private void AdminInstall()
{
var configpath = System.IO.Path.Combine(XJK.ENV.BaseDirectory, Env.GlobalSettingFileName);
if (!File.Exists(configpath))
var globalfile = System.IO.Path.Combine(XJK.ENV.BaseDirectory, Env.GlobalSettingFileName);
if (!File.Exists(globalfile))
{
var setting = DataModel.DefaultSetting.GetGlobal();
Util.Yaml.SaveYaml(configpath, setting);
var templatefile = System.IO.Path.Combine(XJK.ENV.BaseDirectory, Env.GlobalTemplateSettingFileName);
if (File.Exists(templatefile))
File.Copy(templatefile, globalfile);
}
Util.Reg.SetExePath(XJK.ENV.EntryLocation);
Util.Reg.SetLogPath();
Expand Down
11 changes: 11 additions & 0 deletions ShellCommand/MenuDefinition/BuildinMenuItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ public static ToolStripMenuItem InitDirectoryFile(string path)
return item;
}

public static ToolStripMenuItem OpenGlobalSetting()
{
var item = new ToolStripMenuItem(Env.OpenGlobalSettingFileText);
item.Click += (sender, args) =>
{
var path = Path.Combine(Env.GetAppFolder(), Env.GlobalSettingFileName);
Cmd.RunAsInvoker(path, "");
};
return item;
}

public static ToolStripMenuItem OpenApp()
{
var path = Util.Reg.GetExePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected override ContextMenuStrip CreateMenu()
container.DropDownItems.Add(new ToolStripSeparator());
}

var globalSettingPath = Path.Combine(Util.Reg.GetAppFolderPath(), Env.GlobalSettingFileName);
var globalSettingPath = Path.Combine(Env.GetAppFolder(), Env.GlobalSettingFileName);
if (File.Exists(globalSettingPath))
{
var globalItems = CommandFileParser.ParseGlobalCommand(globalSettingPath, FolderPath);
Expand All @@ -54,6 +54,8 @@ protected override ContextMenuStrip CreateMenu()
{
container.DropDownItems.Add(BuildinMenuItems.InitDirectoryFile(CommandFilePath));
}

container.DropDownItems.Add(BuildinMenuItems.OpenGlobalSetting());
container.DropDownItems.Add(BuildinMenuItems.OpenApp());

menu.Items.Add(container);
Expand Down
3 changes: 3 additions & 0 deletions ShellCommand/ShellCommand.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@
<None Include=".shellcommand.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="global.template.shellcommand.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
Expand Down
5 changes: 0 additions & 5 deletions ShellCommand/Util/Reg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,5 @@ public static string GetExePath()
return key.GetValue(ExePath) as string;
}
}

public static string GetAppFolderPath()
{
return Path.GetDirectoryName(GetExePath());
}
}
}
20 changes: 20 additions & 0 deletions ShellCommand/global.template.shellcommand.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# ShellCommand: https://github.com/XUJINKAI/ShellCommand

GlobalCommands:
- Name: Open SourceTree Here
Command: cmd /c start %LocalAppData%\SourceTree\SourceTree.exe -f "%DIR%"
Match: .git

- Command: git pull
Match: .git
- Command: git submodule update --init --recursive
Match: .gitmodules

- Name: Open Command Window Here
Command: cmd
- Name: Open Command Window Here (Administrator)
Command: cmd /K "cd /d ""%DIR%"""
RunAsAdmin: true

Functions:
CopyPath: true

0 comments on commit ba512ea

Please sign in to comment.