How to search with case sensitive with ag in MAC? - ag

i want to search with case sensitive, seems "ag -i" should do the job.
But when i run it in MAC, seems it's not the case.
Anyone has same issues ?

ag -s pattern
this works in MAC.

Related

how to make filename match in mksh case insensitive

I'm using mksh (the MirBSD Korn Shell) on Windows 10. I'm used to the old UWin ksh not caring about case on Win7, and have been tripped up several times when 'ls' doesn't see a file because of casing:
PC> ls *old
ls: cannot access '*old': No such file or directory
PC> ls *OLD
filename.OLD testing.OLD
I've tried "set completion-ignore-case on", "typeset -l", "shopt -s nocaseglob" and similar bash-isms. What will work for ksh?
Note: This is not a request for case insensitivity in regexps.
Thanks
mksh developer here.
This is not going to happen (especially not as filesystems are usually case-sensitive, and can be set to be it even on Windows/NT and Mac OSX).
You can glob case-insensitively explicitly with ls *.[Oo][Ll][Dd], but that’s it.

Trying to color code g++

My g++ compiler for some reason shows all errors and warnings to be white, making spotting them very tough. I'm open to anything that is easy to implement. I have come across two solutions, none of which I can implement successfully, and hence I'm here:
Option 1:
I've read that the best choice is colorgcc: https://github.com/johannes/colorgcc
I have gone through basically all the posts on how to set it up, but am still having trouble. Here's what I have done so far.
I'm new to programming, so I couldn't understand a lot of it. But this is what I've done so far. I've tried to follow what other people have posted to the best of my knowledge but to no avail.
~$ vim .colorgcc (copy pasted the colorgcc perl script in here)
~$ chmod +X .colorgcc
/usr/bin$ g++ -> colorgcc
-bash: colorgcc: Permission denied
Option 2:
I've also read this post: Is there an easy way to COLOR-CODE the compiler outputs?
but not sure I understand where to copy paste the code that is shown in the best answer.
I think the reason why I can't set this up is because there is a lot that I don't understand, so if you could provide a more beginner like answer, it would be much appreciated.
I have a gcc version of 5.0. And I'm using a Mac OS X 10.10.
Thanks in advance!
I got colorgcc working just fine with the following:
~$ wget https://raw.githubusercontent.com/johannes/colorgcc/master/colorgcc.pl
~$ chmod +x colorgcc.pl
~$ sudo cp colorgcc.pl /usr/local/bin/colorgcc
~$ cd /usr/local/bin
~$ sudo ln -s colorgcc g++
If you are using gcc > 4.9 the compiler should be able to output color error messages. The option to configure this is -fdiagnostics-color[=WHEN]. This should work just fine in the terminal application in OSX.
For previous versions of gcc, there are external tools (filters) like colorgcc that will be able to colorize the output for you. You can take a look at wavemode answer for how to set up colorgcc.

How can I detect when I'm on a system running Unity?

In order to choose between what type of app indicators to use for a program, I need to detect whether I'm in a Unity desktop or not. Is this possible? Is it possible when I don't have access to the environment?
It looks like there's also XDG_CURRENT_DESKTOP:
rubiojr#rubiojr-VirtualBox:~$ echo $XDG_CURRENT_DESKTOP
Unity
See https://askubuntu.com/questions/70296/is-there-an-environment-variable-that-is-set-for-unity
In Ubuntu you can use following commands:
echo $DESKTOP_SESSION: This command return ubuntu when you are using Unity and ubuntu-2d when you are using Unity 2D and ...
sudo grep "Starting session" /var/log/lightdm/lightdm.log: Because of last version of Ubuntu use lightdm as display manager you can see last line of the lightdm.log file.
Just shell execute ps aux | grep unity, this is cross-plattform for linux. Even works on ARM cores.
On my 11.04 Ubuntu running unity it returns unity-2d-panel, unity-2d-launcher and more processes. Can't confirm if this is true on every linux platform.
Look in the list of environment variables for unity by running this command line:
env | grep -i unity
If as in this answer you see XDG_CURRENT_DESKTOP=Unity then you know it is in use. Alternatively, you could of course check for desktop rather than unity.

in the code (.c file) how I can find the linux distribution name version

I'd like to know in the code (.c file) how I can find the linux distribution name version (like ubuntu 10.0.4, or centOS 5.5...)?
The c function that I'm looking for should be like the uname() system call used in (.c files) to get kernel version.
it will be appreciated that the function is working for all linux distribution (standard)
I 'm not looking to get distribution name and version by the use of command line linux from code (.c file) (like the use of system("cat /etc/release");).
Any suggestion will be appreciated!
Regards
There is no standard for this yet. You can query following files or check for existence:
/etc/lsb-release
/etc/issue
/etc/*release
/etc/*version
Well, you can (and should) use fopen and fgets instead of system("cat"), for reading /etc/release.
There's no universal method though, I can even build a linux image which has no filesystem at all (except initramfs) and definitely no distribution name.
AFAIK there isn't a standard system call to get this if uname(2) doesn't give you enough info.
Safest approach is probably to check for "/proc/version" and read that
You could fopen("/etc/lsb-release") and parse its contents. It looks like this:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.04
DISTRIB_CODENAME=lucid
DISTRIB_DESCRIPTION="Ubuntu 10.04.3 LTS"
This method is not universal. You'll need to make sure that it works on all distros that you care about (if it doesn't, I suggest you go with #ott--'s answer).
Is it acceptable to run some shell commands?
$ /usr/bin/lsb_release -r
Release: 11.04
$ /usr/bin/lsb_release -d
Description: Ubuntu 11.04
$ /usr/bin/lsb_release -rd
Description: Ubuntu 11.04
Release: 11.04
There is no portable way to do that, you'll have to use some OS detection tool/library.
Fortunately, there are a few out there. I know those 2 :
Facter, a professional (yet free/open) information gathering program in ruby : http://puppetlabs.com/puppet/related-projects/facter/
a shell script : http://www.novell.com/coolsolutions/feature/11251.html
(I used facter via puppet and it is very good.)
With a little additional scripting, you can use one of those program's output to generate a .h that you can then use in your code.
You can even integrate this generation as a step in your makefile.
I usually inspect /etc/issue; while (as others pointed out) it is not guaranteed, I've fount in the field that's quite reliable.
As far as I've experienced, it works on ubuntu, debian, redhat, centos, slackware and archlinux.

Mac OSX and Unix quick questions

I have 3 questions. I am making a C++ executable to launch a Perl program I made. I will compile it for Winows, Mac OSX and Linux. It's pretty much just: system("perl progam.pl");
When compiled with Mac OSX, the program starts in ~. How would I get it to start in the dir it was launched from, or is it just a problem with the compiler?
I'm using - echo -n -e "\033[0;Program\007" - in an attempt to make the windows title "Program". Is this is best way?
I'm using - echo -n -e "\033[7;30;47m" - to make the background of the window black. Is this the best way?
Thanks.
This sounds like something Finder is doing. Launching the app from a shell should work as you expect.
Use tput
See answer to 2, above.
On Mac OS/Unix, invoking system does not change the current working dir. When executing program.pl the current working directory is the same from which you executed the C++ executable. When you launch the executable using Launch Services (e.g. the Finder) the working directory should be /.
On #1 you can refer to the current directory with ./ so system("perl ./progam.pl"); should do it assuming both scripts are sitting in the same folder. ../program.pl would be one level higher.
For #1, use getcwd & then pass an explicit path to system:
cwd=getcwd(NULL, PATH_MAX);
sprintf(cmd, "perl %s/program.pl", cwd);
system(cmd);
free(cwd);
If your perl program itself relies on a specific working directory, then do this instead:
sprintf(cmd, "cd %s && perl program.pl", cwd);
This is probably a silly question, but why are you making an application to launch a perl script? Just add the following to the top of your perl script and use "chmod a+x" to make it executable:
#! /usr/bin/perl
When you use the system command from C and C++, you are basically launching the default system shell and executing the given command in that shell. Doing that is not very portable and somewhat defeats the purpose of using C or C++ (since you could simply create a shell script that does the same thing). If you want to actually do this with C++, you should probably use popen or fork+exec to launch perl. Generally speaking, it isn't nice to end users to play with their Terminal in the manner that you have proposed; most users, by default, have the Terminal configured to display the most recently executed command or their current directory or some other information of their choosing, and changing that is -- on UNIX systems such as Mac OS X and Linux -- considered improper etiquitte. If you are trying to create a terminal interface, though, you might want to look at the curses library.