terça-feira, 5 de maio de 2015

Append suffix in linux file names with Shell Parameter Expansion

Well, everytime I read about shell (bash) parameter expansion I see examples ripping off the suffixes. But someday, I needed to do the inverse: Append suffixes. How to do that?

I've made a simple bash script to do so:

#!/bin/bash
for i in *; do 
mv ${i} ${i}.sh;
done
exit 0


Using a for loop, I moved every file in the directory to the same name, with a ".sh" appended as suffix.

Feel free to change the suffix you want.

To revert:

#!/bin/bash
for i in *; do
mv ${i} ${i/.sh/};
done
exit 0

In this case, in every file of the directory, ".sh" will be substituted for nothing. It may cause some troubles. Let's suppose you have a dir, full of these files:

1.shellvpower
2.shellvpower
3.shellvpower
4.shellvpower

They'll become:

1ellvpower
2ellvpower
3ellvpower
4ellvpower

So, in a better way, to remove only the suffixes ".sh":

for i in *; do 
mv ${i} ${i%%\.sh};
done
exit 0

Bonus:

Append prefixes:

To append, for instance, prefix "waka":

#!/bin/bash
for i in *; do
mv ${i} ${i/#/waka};
done

Tip: "#" is before "i" (so,  prefix). "%" would be after "i".

It also can be done in a simpler way:

#!/bin/bash
for i in *; do
mv ${i} waka${i};
done


That's all, folks!! 

terça-feira, 17 de março de 2015

Ultimate Guide for good Looking Fonts on Opensuse (13.2) - without Infinality

Well, as I'm using opensuse 13.2 as OS in one of my disks, let's see how we can improve the look of its horrible fonts.

First: Yast2>/etc/sysconfig editor>Desktop, as seen below: 



Play with font configs in each field. Mine I set as below:

FORCE_HINTSTYLE: hintfull
FORCE_AUTOHINT: yes
FORCE_BW: no
FORCE_BW_MONOSPACE: no
USE_LCDFILTER: lcddefault
USE_RGBA: rgb

These settings will make the links on /etc/fonts/conf.d, disabled by default on opensuse. Other way to make this, as root:

cd /etc/fonts/conf.d/
ln -s /usr/share/fontconfig/conf.avail/10-autohint.conf
ln -s /usr/share/fontconfig/conf.avail/10-sub-pixel-rgb.conf
ln -s /usr/share/fontconfig/conf.avail/11-lcdfilter-default.conf


Make a file named user.js in  $HOME/.mozilla/firefox/*.default/ with this content:

user_pref("font.FreeType2.enable", "true");
user_pref("font.FreeType2.autohinted", "true");
user_pref("font.FreeType2.printing", "true");
user_pref("font.FreeType2.unhinted", "false");


To improve fonts and other enhancements on firefox, I use the excellent ArchWiki, mainly for dpi adjustments (I'm not a fanboy of just one distro but since I'm linux user since 1997, I understand distros are just some kind of free expression to get the same thing, like religions, and btw I used arch, made good friends and learn a lot from some years because of the experience, but the rolling release model doesn't fit on the plans of my server). Here's the link: Firefox tweaks on ArchWiki

Add some related lines to Xdefaults, if it doesn't have:

echo -e "Xft.autohint: 1\nXft.lcdfilter: lcddefault\nXft.hintstyle: hintfull\nXft.hinting: 1\nXft.antialias: 1\nXft.dpi: 144\nXft.rgba: rgb" >> ~/.Xdefaults

As I use a 1920x1080 monitor resolution, I use dpi=144, so pay attention to this set on .Xdefaults above and set accordingly to your own set.

And because of that, I made a xrandr.desktop to set dpi through xrandr as well, to autostart in LXDE:

[Desktop Entry]
Name=Xrandr
Terminal=true
Type=Application
Exec=xrandr --dpi 144


In lxappearance (LXDE), I set like this:



Result:











That's all. I hope this simple tuto helps the other Opensuse users with the bad looking fonts on this great distro (IMHO).   



sexta-feira, 7 de março de 2014

Autostarting apps with LXDE

In a term:

#touch .config/lxsession/LXDE/autostart
#cat .config/lxsession/LXDE/autostart
@pcmanfm

Now, LXDE will load pcmanfm on its start. Simply put what you want on the lines (apps), just remembering to put "@" before entry.

That's it!

Adding sound to LXDE start

Simple.

Make a .desktop file and put it in ~/.config/autostart (if this dir doesn't exist, then create it):
# mkdir ~/.config/autostart
#touch ~/.config/autostart/sound.desktop

As you see, my file's named sound.desktop

Which contents may be:

[Desktop Entry]
Name=Sound
Terminal=true
Type=Application
Exec=mplayer /home/pibarnas/Downloads/221359__melliug__newmessage.mp3

I've downloaded mine from freesound.org. There's a lot of sounds there. Enjoy!


segunda-feira, 29 de abril de 2013

Shutting down or restarting using openbox (with chroot)

First, your user must be allowed to shut down the system. Do it editing /etc/sudoers (a glance at man should help). We don't focus the edition of sudoers here. Then, add to you rc.xml (making backup of it first, always):

<keybind key="C-A-Delete" chroot="true">
      <keybind key="r">
        <action name="Execute">
          <prompt>Reiniciar o sistema?</prompt>
          <execute>reboot</execute>
        </action>
      </keybind>
      <keybind key="x">
        <action name="Execute">
          <prompt>Desligar o sistema?</prompt>
          <execute>poweroff</execute>
        </action>
      </keybind>
      <keybind key="Escape">
        <action name="BreakChroot"/>
      </keybind>

Doing so, when pressing ctrl+alt+del you'll be sent into a chroot that allows you to press x or r, the first will prompt a message to shutdown the system and the other, to restart it. If "yes" is chosen, the magic's done. Hope you like the tip.

Aero Snap in Openbox (with or without chroot)

There's quite some time I've been searching on how to do that and I finally found it. First, backup your $HOME/openbox/rc.xml. Then, insert these lines in your rc.xml in keyboard section, before </keyboard> , of course:

 </keybind>
    <keybind key="C-W-1">
      <action name="UnmaximizeFull"/>
      <action name="MaximizeVert"/>
      <action name="MoveResizeTo">
        <width>50%</width>
      </action>
      <action name="MoveToEdgeWest"/>
    </keybind>
    <keybind key="C-W-2">
      <action name="UnmaximizeFull"/>
      <action name="MaximizeVert"/>
      <action name="MoveResizeTo">
        <width>50%</width>
      </action>
      <action name="MoveToEdgeEast"/>
    </keybind>
    <keybind key="C-W-3">
      <action name="UnmaximizeFull"/>
      <action name="Maximize">
        <direction>horizontal</direction>
      </action>
      <action name="MoveResizeTo">
        <height>50%</height>
      </action>
      <action name="MoveToEdgeNorth"/>
    </keybind>
    <keybind key="C-W-4">
      <action name="UnmaximizeFull"/>
      <action name="Maximize">
        <direction>horizontal</direction>
      </action>
      <action name="MoveResizeTo">
        <height>50%</height>
      </action> </keybind>
        </keybind>
    <keybind key="C-W-w" chroot="true">
      <keybind key="Left">
        <action name="UnmaximizeFull"/>
        <action name="MaximizeVert"/>
        <action name="MoveResizeTo">
          <width>50%</width>
        </action>
        <action name="MoveToEdgeWest"/>
      </keybind>
      <keybind key="Right">
        <action name="UnmaximizeFull"/>
        <action name="MaximizeVert"/>
        <action name="MoveResizeTo">
          <width>50%</width>
        </action>
        <action name="MoveToEdgeEast"/>
      </keybind>
      <keybind key="Down">
        <action name="UnmaximizeFull"/>
        <action name="Maximize">
          <direction>horizontal</direction>
        </action>
        <action name="MoveResizeTo">
          <height>50%</height>
        </action>
        <action name="MoveToEdgeSouth"/>
      </keybind>
      <keybind key="Up">
        <action name="UnmaximizeFull"/>
        <action name="Maximize">
          <direction>horizontal</direction>
        </action>
        <action name="MoveResizeTo">
          <height>50%</height>
        </action>
        <action name="MoveToEdgeNorth"/>
      </keybind>
      <keybind key="Escape">
        <action name="BreakChroot"/>
      </keybind>
    </keybind>

  
An openbox --reconfigure in the terminal will make it available in your openbox, after inserting the code into rc.xml file. The code enables two methods of doing aero-snapping: The first one allows you to make aero-snapping  pressing ctrl+windows+1 to 4. The second one, pressing in the same time ctrl+windows+w you will be sent to a chroot and you can move windows with keyboard directionals (up, down, right and left), and escaping with "esc". Thanks for the idea, folks from Crunchbang forum!! I slightly change it, but it works like a charm! Hope it'll be useful for everyone! .

quarta-feira, 28 de setembro de 2011

Novo Openbox 3.5.0 e os meus arquivos de configuração

Bom, sem delongas, eis o meu novo desktop openbox, compilado do código fonte no meu Fedora 15. Eis seus menurc.xml e autostart.sh para os leitores examinarem, adaptarem e usarem. Abraços!