I am trying to determine WHAT console I am running in. (Exceptionally hard based on the research I have done so far.) The latest feature that I discovered that would be useful is Double High, Double Wide for a couple of scenarios.
The setup is a Kubuntu 15.04 machine with native (lower) and remote access via Terminal.app on OS X 10.10.4.
Based on vt100.net Apple is doing the right thing.
#!/bin/bash
# Cool effect with OS X Terminal.app
# Not as much on others (Like Konsole)
function embiggen()
{
# Yellow (Darker) foreground
# | Black backround
# | |
printf "\x1b[38;5;226m\x1b[48;5;0m"
# Double high 'top anchor'
# | line down
# | | Start of line
# | | |
printf "\x1b#3$1\x1b[B\x1b[G"
# Yellow (Bright) foreground
# | Red background
# | (Bright) |
printf "\x1b[38;5;229m\x1b[48;5;196m"
# Double high 'bottom anchor'
# | line down
# | | Start of line
# | | |
printf "\x1b#4$1\x1b[B\x1b[G\n\n"
}
clear
embiggen "Hello, World"
With Konsole
With Konsole the rendering seems to be controlled from bottom to top. i.e. each line is drawn bottom to top basically topmost line wins. However, repaints are less than predictable.
Is it remotely possible to use some of the extended features in a reasonably gracefully degraded way when the terminal doesn't support extended formating?
Best 'solution' I have thought of is using a custom entry point with
ssh -i ... usr#svr.dom bash --init-file osx_remote -i
The short answer, is "no" - this is not possible using just escape sequences.
You cannot tell whether the terminal actually displays double-sized characters. Using the cursor-position report, you can tell (except for buggy implementations) if the terminal used two cells on the screen to represent a double-width character. xterm did that long ago; other terminals do that.
Double-sized characters are a VT100 feature, so they are not listed in a device attributes response either. That would be of limited use, since some terminal emulator developers simply cut/paste responses to make them satisfy applications which check for specific features.
If you were running locally (rather than via ssh), conceivably you could write a program which did an X Window dump and analyzed that picture.
Related
OK, so I want to start by first explaining my setup. I have a windows desktop at home, and I am SSH'ing into an Amazon EC2 instance (via PuTTY) running Amazon Linux. I have zsh as my default shell, and oh-my-zsh installed as well. This "cloud developer desktop" model works well for me, but I am having one problem that I have poured more time into than I care to admit: GNU screen only shows 'zsh' as the title of every tab. This is despite using oh-my-zsh's screen plugin (which I think isn't doing anything). Anyone able to help me out? I'd love to have something more descriptive in the tab, perhaps just the last x characters of the current directory (or an open file name if one is open in vim).
Like many screen users, I've had what I'm asking for before, but on a new rig now and don't fully understand everything in my .screenrc:
# Many settings from https://gist.github.com/azitabh/7427682 and
# https://gist.github.com/joaopizani/2718397 and
# https://gist.github.com/ChrisWills/1337178
# Allow bold colors - necessary for some reason
attrcolor b ".I"
# Tell screen how to set colors. AB = background, AF=foreground
termcapinfo xterm "Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm"
# Erase background with current bg color
defbce "on"
# Cache 30000 lines for scroll back
defscrollback 30000
# add tabs on bottom
caption always "%{= bb}%{+b w}%n %t %h %=%l %H %c"
# Very nice tabbed colored hardstatus line
#hardstatus string '%{= Kd} %{= Kd}%-w%{= Kr}[%{= KW}%n %t%{= Kr}]%{= Kd}%+w %-= %{KG} %H%{KW}|%{KY}%101`%{KW}|%D %M %d %Y%{= Kc} %C%A%{-}'
hardstatus alwayslastline "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<"
#Remove vim buffer from scrollback history after quitting
altscreen on
# special xterm hardstatus: use the window title.
#termcapinfo xterm 'hs:ts=\E]2;:fs=\007:ds=\E]2;screen\007'
#termcapinfo xterm 'hs:ts=\E]2;:fs=\007:ds=\E]1;screen\007'
# Enable 256 color term
term xterm-256color
# Enables use of shift-PgUp and shift-PgDn
termcapinfo xterm|xterms|xs|rxvt ti#:te#
# tell screen that xterm can switch to dark background and has function keys.
termcapinfo xterm 'VR=\E[?5h:VN=\E[?5l'
termcapinfo xterm 'k1=\E[11~:k2=\E[12~:k3=\E[13~:k4=\E[14~'
termcapinfo xterm 'kh=\E[1~:kI=\E[2~:kD=\E[3~:kH=\E[4~:kP=\E[H:kN=\E[6~'
# window numbering starts at 1 not 0
bind c screen 1
bind 0 select 10
screen 1
#allow mouse scrolling in screen
termcapinfo xterm* ti#:te#
# Automatically detach on hangup.
autodetach on
I also tried adding this to my .zshrc, and it helps, but isn't quite what I want, as if you run ls, now your title is ls. Ie, not very informative. But maybe editing here is actually the right way to go:
# So screen tabs receive running process title
# preexec () {
# echo -ne "\ek${1%% *}\e\\"
# }
Thanks in advance for your help!
Answering my own question a bit here:
Replacing the line in the preexec () function above with this helps:
echo -ne "\ek$(pwd)\e\\"
Would still be best to only grab the characters from the x-to-last '/' to the end though, replacing the initial string with '...'
I have a Mac App (CodeRunner) that executes a script in login mode and shows the output in a window.
In error condition, it returns the code with escape characters to make the output hard to read.
Is there a way to process the color code? Is there a filter to remove the color code?
With Mac OS X, I used stderred library.
#export DYLD_INSERT_LIBRARIES="/LOCATION_OF_THE_LIB/libstderred.dylib${DYLD_INSERT_LIBRARIES:+:$DYLD_INSERT_LIBRARIES}"
Removing this library setup shows the strings without the code.
If I understand your question, the easiest way to control color in bash (or any terminal that supports them) is with ANSI escape sequences. Example:
#!/bin/bash
blue='\e[0;34m' # ${blue}
green='\e[0;32m' # ${green}
nc='\e[0m' # ${nc} (no color - disables previous color selection)
printf "${blue}This text is blue, ${green}this is green${nc}\n"
exit 0
There are a number of complete references for the ANSI sequences available on the web, but for basic colors, the following is generally sufficient:
black='\e[0;30m' # ${black}
blue='\e[0;34m' # ${blue}
green='\e[0;32m' # ${green}
cyan='\e[0;36m' # ${cyan}
red='\e[0;31m' # ${red}
purple='\e[0;35m' # ${purple}
brown='\e[0;33m' # ${brown}
lightgray='\e[0;37m' # ${lightgray}
darkgray='\e[1;30m' # ${darkgray}
lightblue='\e[1;34m' # ${lightblue}
lightgreen='\e[1;32m' # ${lightgreen}
lightcyan='\e[1;36m' # ${lightcyan}
lightred='\e[1;31m' # ${lightred}
lightpurple='\e[1;35m' # ${lightpurple}
yellow='\e[1;33m' # ${yellow}
white='\e[1;37m' # ${white}
nc='\e[0m' # ${nc} (no color - disables previous color selection)
Note: always reset the color to default at the end of a string with ${nc} ('\e[0m') to prevent continuation of the color after your script finishes. Lastly, if using echo, you must use echo -e to process the ANSI codes.
Note2: since you are seeing the codes and not the color, you have several possibilities (1) you are using echo without the -e option to allow proper interpretation of the codes (or something similar); or (2) the terminal you are using lacks color capability (though that is doubtful, as just about all modern terminals are VT based with default color handling available).
As suggesting by the comments below, you can also set color with tput (setab # for background and setaf # for foreground).
How can I make bash script have a cool title
Currently I am just using echo to give the name arg cliccker to my script
instead of having one boring line
how do i make fnacy bash sript logos
like this below:
Take a look at tput commands. tput is used to alter the terminal characteristics.
e.g
tput bold
tput setaf 3
tput setab 4
tput reset
There are some website that can do it.
Check out this website:
http://www.kammerl.de/ascii/AsciiSignature.php
Try installing 'boxes' - From the man page:
DESCRIPTION Boxes is a text filter which can draw any kind of box
around its input text. Box design choices range from simple boxes to
complex ASCII art. A box can also be removed and repaired, even if it
has been badly damaged by editing of the text inside. Since boxes may
be open on any side, boxes can also be used to create regional
comments in any programming language. New box designs of all sorts
can easily be added and shared by appending to a free format
configuration file. boxes was originally intended to be used with the
vim(1) text editor, but it can be tied to any text editor which
supports filters, as well as called from the command line as a
standalone tool.
$ boxes -h
boxes - draws any kind of box around your text (and removes it)
(c) Thomas Jensen <boxes#thomasjensen.com>
Web page: http://boxes.thomasjensen.com/
Usage: boxes [options] [infile [outfile]]
-a fmt alignment/positioning of text inside box [default: hlvt]
-c str use single shape box design where str is the W shape
-d name box design [default: first one in file]
-f file configuration file
-h print usage information
-i mode indentation mode [default: box]
-k bool leading/trailing blank line retention on removal
-l list available box designs w/ samples
-m mend box, i.e. remove it and redraw it afterwards
-p fmt padding [default: none]
-r remove box
-s wxh box size (width w and/or height h)
-t str tab stop distance and expansion [default: 8e]
-v print version information
:)
Dale
So I know how to find the number of the video cards but in a ruby script I wrote I had this small little method to determine it:
def getNumCards
_numGpu = %x{lspci | grep VGA}.split("\n").size
end
But have determined I need to do a search for 3D as well as VGA so I changed it to:
def getNumCards
_numGpu = %x{lspci | grep "VGA\|3D"}.split("\n").size
end
But I am finding it returns 0 when I run the second. If I run the command on it's own on the command line, it shows me 3 video cards (1 on board VGA and two Tesla NVIDIA cards that come up as 3D cards). I am not sure what is happening in the split part that may be messing something up.
Any help would be awesome!
Cheers
man grep:
-E, --extended-regexp
...
egrep is the same as grep -E.
so, egrep should help
I'd go after this information one of two ways.
The almost-purely command-line version would be:
def getNumCards
`lspci | grep -P '\b(?:VGA|3D)\b' | wc -l`.to_i
end
which lets the OS do almost all the work, except for the final conversion to an integer.
-P '\b(?:VGA|3D)\b' is a Perl regex that says "find a word-break, then look for VGA or 3D, followed by another word-break". That'll help avoid any hits due to the targets being embedded in other strings.
The more-Ruby version would be:
def getNumCards
`lspci`.split("\n").grep(/\b(?:VGA|3D)\b/).count
end
It does the same thing, only all in Ruby.
I'm using zenity to post a simple notification when my spam-filter daemon filters a group of messages. Currently this message is posted to the middle of the screen, which is obtrusive. I want to post it to the upper left corner. However, zenity does not honor the -geometry option which is supposed to be standard for all X applications, and its documentation gives options for controlling window height and width, but not placement.
Is there a way to control the (x,y) coordinate at which a zenity window is posted?
If not, is there a way to solve this problem by tinkering with X resources or the window manager (I'm using the fvwm)?
EDIT: The following do not work in ~/.fvwm2rc (fvwm version 2.5.26):
Style "Information" PositionPlacement -0 -0
Style "Zenity" PositionPlacement -0 -0
They also don't work with the -0 -0 dropped, as suggested in the man page.
(The window title for zenity --info is "Information".)
Interestingly, zenity was ignoring my earlier window-manager directive that windows should be placed manually by default.
EDIT:
Among many other fascinating pieces of information, xprop(1) reports this about the zenity window:
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_DIALOG
WM_NORMAL_HINTS(WM_SIZE_HINTS):
program specified location: 0, 0
program specified minimum size: 307 by 128
program specified maximum size: 307 by 128
window gravity: NorthWest
WM_CLASS(STRING) = "zenity", "Zenity"
WM_ICON_NAME(STRING) = "Information"
WM_NAME(STRING) = "Information"
Despite this apparently encouraging report, the window is not in fact posted at the location 0,0 :-(
I know the Style command is taking effect because I added the !Borders option, and sure enough the zenity window posts without borders... but still in the center of the damn screen!
I do it by using wmctrl in a subshell. Example:
((sleep .4;wmctrl -r TeaTimer -R TeaTimer -e 0,50,20,-1,-1)
for ((a=$LIMIT; a > 0; a--)); do
# for loop generates text, not shown
done
wmctrl -R TeaTimer
) | zenity --progress --title="TeaTimer" --percentage=0
First wmctrl moves zenity to upper left, second moves it to
current workspace. See a full example.
You could try using the "old" way of doing this, using FvwmEvent.
AddToFunc StartFunction I Module FvwmEvent FvwmEvent-MoveWindow
DestroyModuleConfig FvwmEvent-MoveWindow: *
*FvwmEvent-MoveWindow: Cmd Function
*FvwmEvent-MoveWindow: add_window MoveZenity
DestroyFunc MoveZenity
AddToFunc MoveZenity
+ I ThisWindow ("zenity") Move -0 -0
If this still doesn't work (or you are determined to get it working using PositionPlacement) you could try
BugOpts ExplainWindowPlacement
Fvwm will then write debugging output to it's logfile (or to the console, depending on your setup) explaining how it is placing windows (and why it is doing so).
Also just fyi, if you want to get information about a window you can use the FvwmIdent module to get this information (instead of xprop, though both work fine).
Yes, it is definitely possible with the proper help from window manager. For example, with xmonad it would be one line of code...
My fvwm is little rusty, but it seems like something along the lines of:
Style "zenity" PositionPlacement -0 -0
in your fvwm2rc should do the trick.
EDIT: Notice the lowercase "zenity" since, according to the docs, it should match not only window title, but window class as well (which you can find out using "xprop" utility: launch it and point to window in question).
According to xprop, zenity window has two interesting properties:
It has _NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_DIALOG, indicating that it is a dialog window
It has WM_TRANSIENT_FOR(WINDOW): window id # <some window id here>, indicating the main window for which it is a dialog (in my case - xterm window)
So, if my suggestion does not work, then it is almost certainly because fvwm handles dialogs in a special way - either due to configuration or due to hardcoded behavoir.
You can try adding "EWMHIgnoreWindowType" to the style of zenity windows, which should hopefuly made fvwm ignore those hints
Try devilspie: http://burtonini.com/blog/computers/devilspie/
You can use wmctrl to get the windowid, then xdotool to place it wherever you want. Simple and adaptable to many types of environments.
## Arg 1 - Pid of window to move.
## Arg 2 - X-Coord.
## Arg 3 - Y-Coord.
function move_win() {
xdotool windowmove $(wmctrl -lp | grep ${1} | cut -d' ' -f1) ${2} ${3}
}
E.g. $> move_win $(pidof zenity) 0 0