How to read text from clipboard? - linux

Is that possible to read text from clipboard on Linux udner X?
I select some text in a browser (Firefox for example) then click Edit->Copy.
Now I need this text in my application. I am using plain XLib. No GTK, no QT.
I do not want to use external apps like xsel. I studiet xsel source code, DAMN it is over 1000 lines. In Windows I am used to GetCLipboardTextW() one function call. That's all I need. Why is this so sophisticated? I have read this already:
http://www.sbin.org/doc/Xlib/chapt_12.html
And some more, I know there are many kinds of clipboards in X, selections, cut buffers etc. It does not help! Give me some code that compiles and works. No external libraries please no sudo apt-get install something, no "Are you using KDE(GNOME/whatever)?".

xclip is just 600 lines of code, but much of it seems to be due to processing command line options, reading input files, etc. Looking at main and doOut the core of what it does seems to be:
XOpenDisplay(...)
XCreateSimpleWindow(...)
XSelectInput(...)
XFetchBuffer(...) or xcout(...)
XCloseDisplay(...)

Related

Stop some software from updating in Manjaro

I have a lot of software in Manjaro 20.0 that I don't use in my day to day use such as GIMP and Thunderbird (and maybe more) but don't really want to uninstall. Is there some way to temporarily freeze them by excluding them from updates as a lot of them can get really heavy.
I'm looking at saving 200-300mb worth of downloads every week if this were possible.
Even though this might be posted on the wrong forum. I'll try to assist you.
First you would need to edit the pacman configuration file using a text editor of your choice. To do this go into the terminal and type the command sudo nano /etc/pacman.conf , once there look for "IgnorePkg" and remove the "#" symbol then add the programs you wish to disable updates for. Once done save the file and exit.

How do I reveal a file as "selected" in *nix from the command line?

Is there a semi-universal mechanism by which to reveal files as selected in various *nix window managers via the command line? For example, in Windows I can say the following:
explorer.exe /select,C:\TestDir\TestFile.txt
…and Explorer will reveal the file and select it for you. In OS X I can say the following:
osascript -e 'Tell application "Finder" to reveal "MacHD:Users:myaccount:Desktop:filename.txt"'
…and it will do the same. My question is, is there any way to do the exact same thing (somewhat universally) in any of the various popular *nix flavors across window managers? Obviously "Open Containing Folder" is simple enough, but I want to go the extra step of actually opening it with the specific file selected. Any assistance is appreciated.
Best.
I don't about other file managers (other answers can add that) but for nautilus it's been recently fixed
This allows to call nautilus
uri:///path/to/file from the command
line to open uri:///path/to with file
pre-selected.
For OSX AppleScript works for all versions, but if you know you'll be dealing with 10.6 or later you'd be better served by using the -R option for "open". It's around 30 times faster.
open -R "/Volumes/Users/Desktop/file-to-open.txt"
For Linux Nautilus allows for direct calling of the file, a generic solution for GNOME (you won't find one for "Linux") is the "gnome-open" command, which currently could open the directory but won't highlight the file:
"gnome-open /tmp/file.txt"

Ubuntu terminal in windows ? Can anyone explain the 'col' command in plain English for me?

Next week I am getting an exam on using basic commands and shell scripting using terminal in Ubuntu. Please help me out with two quick questions:
-Does a practice environment for the Ubuntu terminal exist? I don't want to dual boot with Linux, so I want to find somewhere I could practice using some basic terminal commands as Cygwin seems to be quite different from the ubuntu terminal.
-What does the col command in Linux do? The manual page is here: Link, but I find that hard to understand, and since it doesn't work in Cygwin, it's hard to interpret! Also, why would one use man piped to col -b -x?
Thank you very much and sorry for the probably silly questions!
You can use the Ubuntu LiveCD boot (boots up an Ubuntu system without actually installing it) and experiment with the Ubuntu terminal shell. Its actually the same CD as the standard Ubuntu installtion CD... you just chose "Try Ubuntu" instead of "Install Ubuntu" once it boots up:
https://help.ubuntu.com/community/LiveCD
col is program to filter out reverse-linefeeds (i.e. the backspace character) from text input. In the olden days of line printers, a common method to achieve boldface print was to print a character, then print a backspace character, then print the character again. This would make the printer strike the character twice in the same place. Some programs would emit text files formatted in this way (man is one such program)-- but if you then tried to display that text file to your terminal screen, you might end up seeing something like this: "here is b^Hbo^Hol^Hld^Hd text".
col -b simply filters text input to strip out those extra backspace and double-strike characters. The -x option converts tab characters to space characters, which might be useful if the output was formatted for a device with a particular tab width, but then displayed on a different device.
man pages often have the backspace/double-strike text embedded in them, so man piped into col was often useful.
Nowadays, most terminal emulators actually know how to handle the backspace/double-strike, so col doesn't get used as much.
Far better (easier to use, install, maintain, etc.) than Cygwin, and perhaps less resource-using than a virtual machine, is http://andlinux.org . That will give you a shell on your Windows desktop, and you can play with the col command to better understand it.
Win-bash is essentially the same shell as linux, but on windows. You can use this to experiment outside Linux but I'm not sure how effective it is.
Other options are virtual machines, and if you don't mind a reboot, you can install ubuntu with wubi which means it can be deleted from windows' add/remove programs when you are done with it. (Or just use the live disc)
Col has very limited use for most people, it only affects programs that write lines asynchronously as opposed to line by line...

Make a Linux "GUI" in the command line

How to make a Linux program in the Command Line Interface who display a nice user interface?
For example when I use "wget" to download a file from internet, I can see the download advancement in the Command Line Interface. How can I do that?
ncurses is a popular option, there are APIs for lots of programming languages.
Take a look at curses. It is a library for text based UI.
You can get a basic interface by using \r to go to the beginning of the current line.
Slightly more advanced is ncurses.
The next step up is Newt.
If you want to do a GUI for Bash scripts or to wrap around other command line utilities, you can use dialog (man page).
Here two great dialog tutorial to get you started :
Dialog: An Introductory Tutorial
Improve Bash Shell Scripts Using Dialog.
If you only need a progress bar, this can be done directly with a simple print (that prints the bar), followed by the carriage return character (ANSI character #13), which puts you back at the beginning of the line. The line can then be later updated by printing over it.
For more complicated needs, ncurses is indeed the standard way to go.
I wouldn't call wget's progress report as a 'nice gui', but anyway, the classic library for building graphical interfaces without X Windows is Linux and UNIX systems is ncurses.
Recently a C# version of ncurses has been started, check out details here
If you're using Mono, you could use MonoCurses
Try curses, it is a well documented API for text based UI.Also, there is so much open source projects that are using curses for you see and learn
wget does not really have a GUI, all I see is stuff that you can already achieve using stdout and echos (e.g. printf() or std::cout)
Anyways, for simple dialog boxes of the MessageBox kind, but not limited to that, also have a look at dialog
http://linux.die.net/man/1/dialog
http://hightek.org/dialog/
You can just use ANSI escape codes. A simple example in bash
echo -e "\033[H\033[2J \033[20;20H \033[4mThis is a underlined line.\033[0m"
One should mention FTXUI. Functional Terminal (X) User interface: A simple C++ library for terminal-based user interfaces!
Cross-Platform
Support for UTF8 and fullwidth chars (→ 测试)
No dependencies
etc

linux clipboard read/write in C

I done lots of googling but I am still unsure on how to proceed.
What's the most common way of reading/write to the clipboard under Linux? I want both support for Gnome & KDE desktops.
Updated: do I take there isn't an easy solution and one must "aggregate" together multiple sources (gnome, kde) in order to craft a solution?
Maybe you can look at xclip and see how they have done it.
It provides an interface to X
selections ("the clipboard") from the
command line. It can read data from
standard in or a file and place it in
an X selection for pasting into other
X applications. xclip can also print
an X selection to standard out, which
can then be redirected to a file or
another program.
I might be shooting myself in the foot, but this could give you a hint on how to do the clipboard for kde, not sure about Gnome myself but try it, the script is in python and demonstrates how to get/set stuff on the clipboard, via using dcop and klipper, it is on this site here.
Hope this helps,
Best regards,
Tom.

Resources