-3

Every day I make a GUID which I copy to my clipboard.

I do this by opening my terminal, writing csharp (see link below in case you are confused), writing GUID.NewGuid(), copying the output and writing quit.

Is there any way I can turn this whole procedure into a terminal alias?

Edit:

Just to clarify, I'm using this: https://www.mono-project.com/docs/tools+libraries/tools/repl/

You can write and compile a console application, the question was geared towards whether you can inject statements directly into the command-line tool, not how to make a tiny executable.

  • Where do you copy it to? – ctrl-alt-delor Nov 14 '18 at 12:42
  • So are you saying that you want to do this using the repl, on the web-app? – ctrl-alt-delor Nov 14 '18 at 12:57
  • Where do you copy it to? – ctrl-alt-delor Nov 14 '18 at 13:00
  • No, I'm not using a web-app. The repl runs in my macOS terminal. It's irrelevant where I copy it to for this purpose, you cannot automate the pasting part of the copying. I just need it in my clipboard. – Mathias Siig Nørregaard Nov 14 '18 at 13:02
  • I was asking where you past it to, because you can automate it. I thought that is what you are asking. If you are asking how do I use the same source code, each time, then the answer is to save it into a file. (I am now starting to think that I don't understand what you are asking). Please help by explaining. – ctrl-alt-delor Nov 14 '18 at 13:12
  • Okay I'll explain again: Is it possible to inject statements directly into the csharp command-line repl, and copy outputs from it as well? Yes the particular case at hand can be solved using powershell, a C# script or a C# executable, but I'm curious about the command-line repl itself. Directly as in, something like 'csharp && Guid.NewGuid() && quit' except this doesn't work for obvious reasons – Mathias Siig Nørregaard Nov 14 '18 at 13:14
  • And yes you can automate it but it's totally not worth the hassle. In all the cases with Azure Storage, automation seems to be annoying to maintain in the long run. – Mathias Siig Nørregaard Nov 14 '18 at 13:17
  • Then do it (the MS way) manually. I am very confused now. You want it automated, you don't want in automated. – ctrl-alt-delor Nov 14 '18 at 13:20

3 Answers3

1

There is an easy command from BSD to generate a UUID, it's available in macOS.

uuidgen

If you need to copy the UUID result to clipboard, use this:

uuidgen | pbcopy

So, what's the difference between UUID and GUID? Check out this thread.

Itachi
  • 5,777
  • 2
  • 37
  • 69
  • I was hoping to be able to do it with the csharp repl, however I think this is close enough. The question was more about the flexibility of the command-line tool, so that I could use it and keep my nifty mini-scripts in an alias file instead of having a gross amount of executables or script files lying around. I'll accept this one because it's short and nifty though! – Mathias Siig Nørregaard Nov 14 '18 at 13:22
  • I have that on my Debian as well, but a different clipboard program. – ctrl-alt-delor Nov 14 '18 at 13:24
0

Create a C# program

using System;

namespace guid
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            new MainClass().run();
        }

        private void run()
        {
            Console.WriteLine(Guid.NewGuid());
        }
    }
}

Compile to new-guid

Use in zsh like this

guid=$(./new-guid) #you may have to change the `.` to the appropriate path, depending on where the program is.
echo "${guid}"

Tested with zsh and mono-develop in Debian Gnu/Linux.

Note there are probably better ways to do this. One line purl script, or may be some Unix command.

ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52
0

Here's the answer I was looking for, in this case:

csharp -e 'Guid.NewGuid();' | pbcopy