Windows Vista Forums

A near prompt function I created...
  1. #1


    James Gentile Guest

    A near prompt function I created...

    This prompt function does several things, it puts the username,
    computername, current directory, time, and system uptime in the title, and
    it puts the username, computername, and current directory in the prompt. It
    also uses the unix/linux convention of substituting ~ for the home directory
    (which you can CD to or copy to, etc. in powershell, e.g. "cd ~\"). Thought
    someone might enjoy this. Oh, one more thing, the special ASCII characters
    require consolas font be used.

    function prompt
    {
    $computer = get-WMIObject -class Win32_OperatingSystem -computer "."
    $lastboottime=[System.Management.ManagementDateTimeconverter]::ToDateTime($computer.lastbootuptime)
    $uptime=$(get-date)-$lastboottime

    $upstr="$([datetime]::now.toshorttimestring())
    $([datetime]::now.toshortdatestring()) up $($uptime.days) days,
    $($uptime.hours) hours, $($uptime.minutes) minutes"

    $dir = $pwd.path

    if ($dir -like "$env:userprofile*")
    {
    $dir=$dir.tolower().replace("$env:userprofile".tolower(),'~')
    }

    $retstr = "$env:username@$($env:computername.tolower())?$dir"

    if ($globalriginaltitle -eq $null) {$globalriginaltitle =
    [console]::title}

    [console]::title = "$globalriginaltitle ? $retstr ? $upstr"

    return "$retstr?"
    }




      My System SpecsSystem Spec

  2. #2


    James Gentile Guest

    Re: A near prompt function I created...

    Guess I need unicode, and that should be 'a neat prompt function I created'
    oops

    function prompt
    {
    $computer = get-WMIObject -class Win32_OperatingSystem -computer "."
    $lastboottime=[System.Management.ManagementDateTimeconverter]::ToDateTime($computer.lastbootuptime)
    $uptime=$(get-date)-$lastboottime

    $upstr="$([datetime]::now.toshorttimestring())
    $([datetime]::now.toshortdatestring()) up $($uptime.days) days,
    $($uptime.hours) hours, $($uptime.minutes) minutes"

    $dir = $pwd.path

    if ($dir -like "$env:userprofile*")
    {
    $dir=$dir.tolower().replace("$env:userprofile".tolower(),'~')
    }

    $retstr = "$env:username@$($env:computername.tolower())●$dir"

    if ($globalriginaltitle -eq $null) {$globalriginaltitle =
    [console]::title}

    [console]::title = "$globalriginaltitle ♦ $retstr ♦ $upstr"

    return "$retstr►"
    }


      My System SpecsSystem Spec

  3. #3


    tojo2000 Guest

    Re: A near prompt function I created...

    On Sep 17, 3:49*pm, "James Gentile" <n...@newsgroup> wrote:

    > Guess I need unicode, and that should be 'a neat prompt function I created'
    > oops
    >
    > function prompt
    > {
    > * * * * $computer = get-WMIObject -class Win32_OperatingSystem -computer "."
    > * * * * $lastboottime=[System.Management.ManagementDateTimeconverter]::ToDateTime($ computer.lastbootuptime)
    > * * * * $uptime=$(get-date)-$lastboottime
    >
    > * * * * $upstr="$([datetime]::now.toshorttimestring())
    > $([datetime]::now.toshortdatestring()) up $($uptime.days) days,
    > $($uptime.hours) hours, $($uptime.minutes) minutes"
    >
    > * * * * $dir = $pwd.path
    >
    > * * * * if ($dir -like "$env:userprofile*")
    > * * * * {
    > * * * * * * * * $dir=$dir.tolower().replace("$env:userprofile".tolower(),'~')
    > * * * * }
    >
    > * * * * $retstr = "$env:username@$($env:computername.tolower())●$dir"
    >
    > * * * * if ($globalriginaltitle -eq $null) {$globalriginaltitle =
    > [console]::title}
    >
    > * * * * [console]::title = "$globalriginaltitle ♦ $retstr ♦ $upstr"
    >
    > * * * * return "$retstr►"
    >
    >
    >
    > }
    It seems like a couple of these variables should probably be declared
    in the profile instead of the prompt function. For example, it's
    probably inefficient to query WMI every time the prompt function is
    called.

      My System SpecsSystem Spec

  4. #4
    lemur's Avatar

    Senior Member

    Join Date : Aug 2009
    University of Kentucky
    Posts : 1,534
    Windows Vista Enterprise x64 SP2
    Local Time: 11:51 PM
    usa us kentucky

     

    Re: A near prompt function I created...

    Neat ideas...

    I remember having UNIX commands on my pc. Forget what the name of the program was. Here is something interesting...

    Linux Desktop Environment Coming to Windows Vista - In the future; Windows XP support available for now - Softpedia

      My System SpecsSystem Spec

  5. #5


    tojo2000 Guest

    Re: A near prompt function I created...

    On Sep 17, 6:40*pm, lemur <gu...@newsgroup-email.com> wrote:

    > Neat ideas...
    >
    > I remember having UNIX commands on my pc. *Forget what the name of the
    > program was. *Here is something interesting...
    >
    > 'Linux Desktop Environment Coming to Windows Vista - In the future;
    > Windows XP support available for now - Softpedia'
    > (http://news.softpedia.com/news/Linux...t-Coming-to-Wi...)
    >
    > --
    > lemur
    >
    > Please click on rep icon if I've been of any help.
    > Thanks!
    Chances are, you're thinking of Cygwin. You can also get a lot of the
    unix commands compiled for windows off of the Internet without Cygwin.

      My System SpecsSystem Spec

  6. #6


    Larry__Weiss Guest

    Re: A near prompt function I created...

    tojo2000 wrote:

    > On Sep 17, 6:40 pm, lemur <gu...@newsgroup-email.com> wrote:

    >> Neat ideas...
    >> I remember having UNIX commands on my pc. Forget what the name of the
    >> program was. Here is something interesting...
    >> 'Linux Desktop Environment Coming to Windows Vista - In the future;
    >> Windows XP support available for now - Softpedia'
    >> (http://news.softpedia.com/news/Linux...t-Coming-to-Wi...)
    >>
    >
    > Chances are, you're thinking of Cygwin. You can also get a lot of the
    > unix commands compiled for windows off of the Internet without Cygwin.
    Also the MKS Toolkit.
    Bruce Payette worked for MKS at one time.

    - Larry

      My System SpecsSystem Spec

  7. #7


    James Gentile Guest

    Re: A near prompt function I created...

    Ok, I fixed it:


    $global:wmilocalcomputer = get-WMIObject -class
    Win32_OperatingSystem -computer "."
    $global:lastboottime=[System.Management.ManagementDateTimeconverter]::ToDateTime($wmilocalcomputer.lastbootuptime)


    function prompt
    {
    $up=$(get-date)-$lastboottime

    $upstr="$([datetime]::now.toshorttimestring())
    $([datetime]::now.toshortdatestring()) up $($up.days) days, $($up.hours)
    hours, $($up.minutes) minutes"

    $dir = $pwd.path

    if ($dir -like "$env:userprofile*")
    {
    $dir=$dir.remove(0,$env:userprofile.length).insert(0,'~')
    }

    $retstr = "$env:username@$($env:computername.tolower())●$dir"

    if ($globalriginaltitle -eq $null) {$globalriginaltitle =
    [console]::title}

    [console]::title = "$globalriginaltitle ♦ $retstr ♦ $upstr"

    return "$retstr►"
    }



      My System SpecsSystem Spec

  8. #8


    Robert Aldwinckle Guest

    Re: A near prompt function I created...



    "lemur" <guest@newsgroup-email.com> wrote in message news:c22bca53b6bd954337a3eb318611fa64@newsgroup-gateway.com...

    >
    > Neat ideas...
    >
    > I remember having UNIX commands on my pc. Forget what the name of the
    > program was. Here is something interesting...
    >
    > 'Linux Desktop Environment Coming to Windows Vista - In the future;
    > Windows XP support available for now - Softpedia'
    > (http://news.softpedia.com/news/Linux...ta-77136.shtml)

    Depending on your OS you may already have it available
    as a subsystem...

    http://technet.microsoft.com/en-us/l.../cc772343.aspx

    (Microsoft Search for
    SUA
    )


    ---



      My System SpecsSystem Spec

A near prompt function I created... problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Change to C:\ Prompt from C:\Users\username> Prompt cyberbiker General Discussion 2 27 Nov 2009
customized prompt function Larry__Weiss PowerShell 7 02 Aug 2009
prompt function and the last command entered Larry__Weiss PowerShell 5 31 Jul 2009
Files created by Powershell are over 2X bigger than files created bytext editor or cmd.exe. tom.luxury PowerShell 4 27 May 2008
Prompt Function Poll Keith Hill [MVP] PowerShell 9 27 Nov 2006