As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/

Command Line with visual viewport - does it exist?

DelzhandDelzhand Hard to miss.Registered User regular
edited August 2010 in Help / Advice Forum
I'm constantly losing track of where I'm at when using the command line (which I use heavily). I end up typing ls -al and pwd all the time and was wondering if there exists a utility that will basically show in a some kind of frame the current working directory and all files in it. It doesn't need to be GUI, just some sort of real-time "here's where you are and what's in the directory".

Steam|FFXIV|Switch SW-3472-4893-0802
Delzhand on

Posts

  • TavataarTavataar Registered User regular
    edited June 2010
    I am pretty sure you can configure your command prompt to show which directory you are currently in. I am not sure what to tell you about listing the files : \

    Tavataar on
    -Tavataar
  • DanMachDanMach Registered User
    edited June 2010
    Bash shell.

    Double tab, theres everything in your directory(or the directory you are typing).

    As far as PWD.... just type in PWD. You don't need a new tool, you need to use what tools you already have.

    DanMach on
  • McVikingMcViking Registered User regular
    edited June 2010
    Are you using Linux with the bash shell? If so, then you need to read The Bash Prompt How-To. Printing the working directory in your prompt is pretty easy:
    PS1="\w $ "
    

    If you want to get wacky with it, you can make yourself a shell script like this:
    #!/bin/bash
    ls -l | tail -n 5
    

    name it 'myscript', put it in your PATH, and source it in your bash prompt:
    PS1="\$(myscript) \n\w $ "
    

    You'll now get the last five entries of an 'ls -l' listing and the current working directory in your prompt:
    ~ $ cd
    drwxr-xr-x 13 mcviking mcviking 4096 2010-06-30 10:42 scratch
    drwxr-x---  3 mcviking mcviking 4096 2010-05-24 21:02 sounds
    drwxr-xr-x  2 mcviking mcviking 4096 2010-05-24 19:52 Templates
    drwxr-xr-x  2 mcviking mcviking 4096 2010-05-24 19:52 Videos
    drwxr-xr-x  2 mcviking mcviking 4096 2010-06-30 11:00 wwwbackup 
    ~ $ cd scratch/
    -rw-r--r-- 1 mcviking mcviking     3079 2010-06-29 16:18 Transgressions.m3u
    -rw-r--r-- 1 mcviking mcviking     2869 2010-06-29 16:19 Transgressions.pls
    -rw-r--r-- 1 mcviking mcviking     6891 2010-06-29 16:20 Transgressions.xspf
    drwxr-xr-x 3 mcviking mcviking     4096 2009-12-30 16:45 x64
    drwxr-xr-x 4 mcviking mcviking     4096 2009-12-30 16:45 x86
    ~/scratch $ 
    
    You can also have no end of fun with colors and the like. My $PS1 these days looks like this:
    \[\e[0;36m\]\e(0l\e(B\[\e[0m\][\[\e[1;31m\]\u\[\e[0m\]]\[\e[0;36m\]\e(0q\e(B\[\e[0m\][\[\e[1;33m\]@\h\[\e[0m\]]\[\e[0;36m\]\e(0q\e(B\[\e[0m\][\[\e[0;37m\]\!\[\e[0m\]]\[\e[0;36m\]\e(0q\e(B\e(0q\e(B\e(0q\e(B\e(0q\e(B\e(0q\e(B\e(0q\e(B\e(0q\e(B\e(0q\e(B\[\e[0m\][\[\e[1;33m\]\w\[\e[0m\]]\n\[\e[0;36m\]\e(0m\e(B\[\e[0m\]>
    

    Which only appears insane until you try it. There are some crazy clever example prompts at the end of the how-to. Have fun!

    McViking on
  • DelzhandDelzhand Hard to miss. Registered User regular
    edited June 2010
    Oh, I really like your prompt. Is the number after host the uptime?

    Edit: nope, guess not

    Delzhand on
    Steam|FFXIV|Switch SW-3472-4893-0802
  • McVikingMcViking Registered User regular
    edited June 2010
    The number is the bash history command number. It increments every time you run a command. So if you run a complex command (let's say it has history number 123), and a few prompts later you want to run the same command, you can just run:
    !123
    

    and the shell will execute the command with history number 123. You can combine it with the 'history' command to do tricks like:
    ┌[mcviking]─[@dragonfly]─[1382]────────[~]
    └> history | grep find
      701  cd programs/perl/findpix/
      703  less findpix-gconftool.pl 
     1380  history | grep find
     1382  history | grep find
    ┌[mcviking]─[@dragonfly]─[1383]────────[~]
    └> !701
    cd programs/perl/findpix/
    ┌[mcviking]─[@dragonfly]─[1384]────────[~/programs/perl/findpix]
    └> 
    

    McViking on
  • Joe ChemoJoe Chemo Registered User regular
    edited July 2010
    For a different approach, you could try an ncurses file manager like midnight commander.

    Joe Chemo on
  • Smug DucklingSmug Duckling Registered User regular
    edited July 2010
    DanMach wrote: »
    Bash shell.

    Double tab, theres everything in your directory(or the directory you are typing).

    As far as PWD.... just type in PWD. You don't need a new tool, you need to use what tools you already have.

    Yeah, he already said he uses ls -al and pwd a lot. His point is he doesn't want to have to type these commands constantly to remind himself where he is. Hitting tab-tab all the time will give you RSI.

    Thanks for the condescension though.

    Smug Duckling on
    smugduckling,pc,days.png
  • DelzhandDelzhand Hard to miss. Registered User regular
    edited August 2010
    McViking wrote: »
    The number is the bash history command number. It increments every time you run a command. So if you run a complex command (let's say it has history number 123), and a few prompts later you want to run the same command, you can just run:
    !123
    

    and the shell will execute the command with history number 123. You can combine it with the 'history' command to do tricks like:
    ┌[mcviking]─[@dragonfly]─[1382]────────[~]
    └> history | grep find
      701  cd programs/perl/findpix/
      703  less findpix-gconftool.pl 
     1380  history | grep find
     1382  history | grep find
    ┌[mcviking]─[@dragonfly]─[1383]────────[~]
    └> !701
    cd programs/perl/findpix/
    ┌[mcviking]─[@dragonfly]─[1384]────────[~/programs/perl/findpix]
    └> 
    

    Occasionally when I'm using the up and down arrows to look through previous commands, I'll get 6 letters or so stuck at the beginning of the prompt, like this:

    cd sitwget http://...etc

    where the cd sit is totally ignored, but a bit confusing. Any idea what might be the cause?

    Delzhand on
    Steam|FFXIV|Switch SW-3472-4893-0802
  • McVikingMcViking Registered User regular
    edited August 2010
    I had a missing escape sequence somewhere in that mess, and it was causing line wrap problems with long commands. The bad news is that I never bothered debugging it. The good news is that I made a new, improved prompt with this amazing tool. The new hotness looks like this:
    -[\[\033[0m\]\[\033[0;31m\]\u\[\033[0m\]\[\033[1;37m\]@\[\033[0m\]\[\033[1;33m\]\h\[\033[0m\]\[\033[1;37m\]]-[\[\033[0m\]\[\033[0;32m\]${PWD}\[\033[0m\]\[\033[1;37m\]]-[\[\033[0m\]\[\033[0;36m\]$(ls --si -s | head -1 | awk '{print $2}')\[\033[0m\]\[\033[1;37m\]]-[\[\033[0m\]\[\033[1;35m\]$(temp=$(cat /proc/uptime) && upSec=${temp%%.*} ; let secs=$((${upSec}%60)) ; let mins=$((${upSec}/60%60)) ; let hours=$((${upSec}/3600%24)) ; let days=$((${upSec}/86400)) ; if [ ${days} -ne 0 ]; then echo -n ${days}d; fi ; echo -n ${hours}h${mins}m)\[\033[0m\]\[\033[1;37m\]]-\n-[\[\033[0m\]\[\033[1;34m\]\!\[\033[0m\]\[\033[1;37m\]]-> \[\033[0;0m\]
    

    The downside is that it takes it a moment to run the command that shows disk usage. But it would be easy enough to remove that.

    McViking on
Sign In or Register to comment.