25 October 2018

changing shells

i don't know if this a fedora-specific thing or a newer linux thing, but in the past changing your default shell was as simple as editing the /etc/passwd file. today, there is the chsh which can perform this for you. there is a catch, however. the shell must exist in the /etc/shells file to be allowed to be changed.

to make this work, i needed to add my shell to the /etc/shells file. then i issued the chsh to make my shell change.

$ chsh -l
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
/usr/bin/tmux
/bin/tmux
/usr/bin/xonsh

$ sudo chsh -s /usr/bin/xonsh mock
Changing shell for mock.
Shell changed.

my previous post about xonsh is what led me here. i had manually changed the shell directly in the /etc/passwd file, but then my gnome session did not recognize my user. this was the strange side effect of changing the default shell not on the /etc/shells list. gnome (gdm) started the gnome-initial-setup process which runs when gnome is freshly installed.

and thing are still messed up. the gnome settings > users section shows no one, even though i am logged in under my account. (figuring out how to fix this will be another lesson for a future time.)

23 October 2018

xonsh

there was small thread on the knoxdev's slack account about shells the other day. as i was trying to continue the discussion cleverly using the shell names as regular words in sentences, i did a quick search for available shells from my package manager (i.e. dnf search shell). as i was looking through the results, i found xonsh.

the description listed in my package manager tells me this is what it is:
Description  : xonsh is a Python-ish, BASHwards-compatible shell language and
             : command prompt. The language is a superset of Python 3.4 with
             : additional shell primitives. xonsh (pronounced *conch*) is
             : meant for the daily use of experts and novices alike.
i have toyed around with the idea of using python's interactive shell as my main terminal shell for some time, but i always felt it would be too hard to do some of the simple things, such as file management. sure, i could write equivalent scripts to do those tasks, but i never made the effort.

this accomplishes exactly what i wanted to do. with xonsh, i can do this:

~ $ ls -l gPodder/
total 124
-rw-r--r--. 1 mock mock 90112 Feb 19  2018 Database
drwxrwxr-x. 3 mock mock  4096 Feb 12  2018 Downloads
drwxrwxr-x. 2 mock mock  4096 Feb 19  2018 Logs
-rw-rw-r--. 1 mock mock  2715 Feb 19  2018 Settings.json
-rw-r--r--. 1 mock mock 20480 Feb 19  2018 gpodder.net
~ $ from datetime import datetime
~ $ datetime.now()
datetime.datetime(2018, 10, 23, 8, 35, 50, 863981)

there is much more to xonsh than just this. the full documentation can be found at http://xon.sh.

09 April 2018

python string concatenation is a bad practice

i think because python is a scripting language, people tend to thing it's super fine to do something like this:

>>> val + '-string'

the problem is that the + operator does not do any casting of the variable to make it compatible with the string. this sort of thing will throw an error if the type of val is anything other than a string.

check it:

>>> val = None
>>> val + '-string'
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    val + '-string'
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
>>> '{}-string'.format(val)
'None-string'

>>> val = 4
>>> val + '-string'
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    val + '-string'
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>> '{}-string'.format(val)
'4-string'

now, you could force cast it using str(val), but that seems silly when you can just use the format() method on the string object to handle things for you.

02 March 2018

python is referential

this is often misunderstood about python, especially if you are accustomed to other languages, such as C/C++.

>>> class thing(object):
...     def __init__(self, some):
...         self.some = some
...     def add_on(self, addition):
...         self.some = self.some + addition
... 
>>> a = thing("hello")
>>> print(a.some)
hello

>>> b = a
>>> print(b)
<__main__.thing object at 0x7f9d267cf7f0>
>>> print(a)
<__main__.thing object at 0x7f9d267cf7f0>
>>> print(b.some)
hello

>>> a.add_on(", world")
>>> print(a.some)
hello, world
>>> print(b.some)
hello, world

>>> print(a)
<__main__.thing object at 0x7f9d267cf7f0>
>>> print(b)
<__main__.thing object at 0x7f9d267cf7f0>

28 November 2017

fedora magazine

last week, this interview with fedora magazine (online) was published. thanks to charles profitt for the write up.

https://fedoramagazine.org/mark-mcintyre-fedora/


26 November 2017

read 'em and weep

well, i am finally getting to the point of needing reading glasses.

i recently had my contact prescription adjusted to re-calibrate one eye handling objects less than arm's length and the other focusing at a distance. the focal lengths left a big transition between the two. the adjustment shortened that gap.

the result is a decent, unaided distance focus, but the cost seems to be my reading the closer things. of course, my age plays a factor in this too. i am not dismissing that. i think even if i stopped wearing the lenses at night, i wouldn't regain enough of my near-sightedness to avoid the readers.

as such, i have purchased reading glasses which are compact enough for the case to fit in my pocket. unlike some colleagues, i have no problem accepting this sort of thing in my life. if i need them, i need them.

here's the amazon like to what i picked up:

Reading Glasses 2 Pair Black and Gunmetal Readers Compact Folding Glasses for Reading for Men and Women Case Included +1.25 https://www.amazon.com/dp/B01DKW5P9U?ref=yo_pop_ma_swf
nice and compact!

i knew it was coming. gotta learn to adjust.

23 September 2017

grammar and geeks

ok, let's get a few things straight.

( ) - these are parentheses. no one questions the name of these characters. no one calls them "rounded brackets," for obvious reasons.

[ ] - these are brackets. not square brackets, which is redundant. they are not square braces, if anyone actually calls them that. they are brackets!

{ } - these are braces. not curly brackets. definitely not curly braces (more redundancy).

why is this so confusing for my fellow geeks who pride themselves on being so precise about every other detail in their lives? it's time to learn the proper names of the punctuation which is so commonly used in our lives everyday in order that they don't appear as idiots.

it's not hard. we are not idiots. these are the names. let's use them.